链接:https://ac.nowcoder.com/acm/contest/5666/F
来源:牛客网
题目描述:
For a string x, Bobo defines x∞=xxx…, which is x repeats for infinite times, resulting in a string of infinite length.
Bobo has two strings a and b. Find out the result comparing a∞ and b∞ in lexicographical order.
You can refer the wiki page for further information of Lexicographical Order.
输入描述:
The input consists of several test cases terminated by end-of-file.
The first line of each test case contains a string a, and the second line contains a string b.
- 1≤∣a∣,∣b∣≤1e5
- a, b consists of lower case letters.
- The total length of input strings does not exceed 2×1e6.
输出描述:
For each test case, print "=
" (without quotes) if a∞=b∞. Otherwise, print "<
" if a∞<b ∞, or ">
" if a∞>b∞.
solution:
题意:给你两个字符串,字符串可以进行无限次循环,比较两个字符串的大小
如果两个字符串长度不一样的话,比较最长字符串的两倍就可以得出两个字符串的大小了
#include<bits/stdc++.h> using namespace std; typedef long long ll; char a[100005],b[100005]; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} int main() { while(~scanf("%s%s",a,b)) { ll len1=strlen(a),len2=strlen(b); int maxn=2*max(len1,len2); int flag=0; int i=0; while(maxn--) { if(a[i%len1]==b[i%len2]){i++;continue;} if(a[i%len1]<b[i%len2]) flag=1; else flag=2; break; } if(flag==0)printf("=\n"); else if(flag==1)printf("<\n"); else printf(">\n"); } }