图片说明

代码

#include
#include
#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma warning(disable:4244)
#define PI 3.141592653589793
#pragma GCC optimize(2)
#define accelerate cin.tie(NULL);cout.tie(NULL);ios::sync_with_stdio(false);
#define EPS 1.0e-8
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll read() {
    ll c = getchar(), Nig = 1, x = 0;
    while (!isdigit(c) && c != '-')c = getchar();
    if (c == '-')Nig = -1, c = getchar();
    while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
    return Nig * x;
}
inline void out(ll a) {
    if (a < 0)putchar('-'), a = -a;
    if (a >= 10)out(a / 10);
    putchar(a % 10 + '0');
}
ll phi(ll n)
{
    ll ans = n, mark = n;
    for (ll i = 2; i * i <= mark; i++)
        if (n % i == 0) { ans = ans * (i - 1) / i; while (n % i == 0)n /= i; }
    if (n > 1)ans = ans * (n - 1) / n; return ans;
}
ll qpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}
ll mat_mod;
struct Mat {
    ll m[10][10];
};
Mat Mul(Mat A, Mat B, ll mat_size) {
    Mat res;
    memset(res.m, 0, sizeof(res.m));
    for (int i = 0; i < mat_size; i++)for (int j = 0; j < mat_size; j++)for (int k = 0; k < mat_size; k++)
        res.m[i][j] = (res.m[i][j] + (A.m[i][k] * B.m[k][j]) % mat_mod) % mat_mod;
    return res;
}
Mat mat_qpow(Mat data, ll power, ll mat_size) {
    Mat res;
    memset(res.m, 0, sizeof(res.m));
    for (int i = 0; i < mat_size; i++)res.m[i][i] = 1;
    while (power) {
        if (power & 1)res = Mul(res, data, mat_size);
        data = Mul(data, data, mat_size), power >>= 1;
    }
    return res;
}
#define Floyd for(int k = 1; k <= n; k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
#define read read()
string c(string b, int n, int l)
{
    string res = b;
    for (int i = 0; i < n; i++)res += b;
    return res.substr(0, l);
}
int main()
{
    string a, b;
    while (cin >> a >> b)
    {
        if (a.size() >= b.size())
        {
            a = a + a;
            int la = a.size();
            int lb = b.size();
            int k = la / lb;
            k++;
            b = c(b, k, la);
            if (a > b)cout " << endl;
            else if (a < b)cout << "<" << endl;
            else cout << "=" << endl;
        }
        else
        {
            swap(a, b);
            a = a + a;
            int la = a.size();
            int lb = b.size();
            int k = la / lb;
            k++;
            b = c(b, k, la);
            if (a > b)cout << "<" << endl;
            else if (a " << endl;
            else cout << "=" << endl;
        }
    }
}

思路解析

无限循环并不需要一直循环,只需要让无限循环应该具有的性质体现出来即可。无非也就在关联处会有一些坑点。

咱们要让最大长度的字符串展开二倍。这样所有的细节都会在这个新的字符串中体现。然后让小的字符串一直扩增,直到长度相同。

这时两个新的字符串就能代表这无限循环的字符串了。