标签:
Time Limit: 3000MS | Memory Limit: 10000K | |
Total Submissions: 3416 | Accepted: 1940 |
Description
Input
Output
Sample Input
4 helloworld amandamanda dontcallmebfu aaabaaa
Sample Output
10 11 6 5
Source
/** 题意:给一个串,求最小表示法 做法:串的最小表示法 **/ #include <iostream> #include <algorithm> #include <cmath> #include <string.h> #include <stdio.h> #include <queue> #include <map> #define maxn 10000 + 100 using namespace std; int match(string s) { int i, j, k, l; int N = s.length(); s += s; for(i = 0, j = 1; j < N;) { for(k = 0; k < N && s[i + k] == s[j + k]; k++); if(k >= N) { break; } if(s[i + k] < s[j + k]) { j += k + 1; } else { l = i + k; i = j; j = max(l, j) + 1; } } return i; // cout << i << " --->" << min(i, j) << endl; //return s.substr(i, N); // return min(i, j); } int main() { int T; scanf("%d", &T); while(T--) { int n; string str; string tmp; cin >> str; int tt = match(str); cout << tt + 1 << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenyang920/p/4852588.html