UVALive 4423 String LD 暴力
2015-01-21 10:40
447 查看
A - String LD
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status Practice UVALive 4423
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.
For example, having the list of words aab, abac, and caac, applying the function on the input for the first time results in ab, bac, and aac. For the second time, we get b, ac, and ac. Since in the second step, we have two ac
strings, the condition 2 is true, and the output of your program should
be 1. Note that we do not count the last step that has resulted in
duplicate string. More examples are found in the sample input and output
section.
Input
There are multiple test cases in the input. The first line of each test case is n(1
n
100)
, 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
Sample Output
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status Practice UVALive 4423
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.
For example, having the list of words aab, abac, and caac, applying the function on the input for the first time results in ab, bac, and aac. For the second time, we get b, ac, and ac. Since in the second step, we have two ac
strings, the condition 2 is true, and the output of your program should
be 1. Note that we do not count the last step that has resulted in
duplicate string. More examples are found in the sample input and output
section.
Input
There are multiple test cases in the input. The first line of each test case is n(1
n
100)
, 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
1 2
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> 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 100001 const 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<n;i++) cin>>s[i]; int flag=0; int flag2=0; if(n!=1) while(1) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j) continue; for(int k=0;k<s[i].size();k++) { if(s[i][k]!='(') break; if(k==s[i].size()-1) { flag2=1; break; } } if(s[i]==s[j]) { flag2=1; break; } } } if(flag2==1) break; for(int i=0;i<n;i++) { s[i][flag]='('; } flag++; } flag--; if(flag<0) flag=0; cout<<flag<<endl; } return 0; }
相关文章推荐
- UVALive 6907 Body Building(暴力)
- UVALive 6163(暴力枚举)
- UVALive 5908 Tracking RFIDs(计算几何+数据结构,暴力也可过)
- UVALive 7279 Sheldon Numbers(位运算、暴力)
- uvaLive 3401 Colored Cubes 暴力
- UVALive 6468 Pisano Periods 坑爹暴力
- UVALive - 4356 Fire-Control System 三角函数+暴力+剪枝
- UVALive 6843 Volume Control(暴力压位)
- UVALive 6852 Blanket(暴力)
- UVALive 6912 Prime Switch 暴力枚举+贪心
- 【暴力预处理+剪枝/bitset】Golf Bot UVALive - 6886
- UVALive 6893 The Big Painting(二维hash,暴力)
- 【dp/二分+暴力】MAGRID UVALive - 5983
- UVALive - 3695 Distant Galaxy 暴力
- UVALive 7279 Sheldon Numbers (暴力打表)
- UVALive - 7457 Discrete Logarithm Problem 费马小定理+暴力枚举+快速幂
- UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)
- UVALive 6862 Triples (找规律 暴力)
- UVALive 7279 Sheldon Numbers(位运算、暴力、想法)
- UVALive - 4848 Tour Belt(暴力+最小生成树)