A - String LD
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description
Stringld(left delete) is a function that gets a string and deletes its leftmost character (for instance Stringld(``acm") returns ``cm").
You are given a list of distinct words, and at each step, we apply stringld on every word in the list. Write a program that determines the number of steps that can be applied until at least one of the conditions become true:
- A word becomes empty string, or
- a duplicate word is generated.
Input
There are multiple test cases in the input. The first line of each test case is n(1n100) , the number of words.
Each of the next n lines contains a string of at most 100 lower case characters.
The input terminates with a line containing `0'.
Output
For each test case, write a single line containing the maximum number of stringld we can call.
Sample Input
4 aaba aaca baabcd dcba 3 aaa bbbb ccccc 0
Sample Output
12
#include#include #include #include #include #include #include #include #include #include #include #include typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 100001const int inf=0x7fffffff; //无限大//string &erase(int pos = 0, int n = npos);//删除pos开始的n个字符,返回修改后的字符串string s[1001];int main(){ int n; while(cin>>n) { if(n==0) break; for(int i=0;i >s[i]; int flag=0; int flag2=0; if(n!=1) while(1) { for(int i=0;i