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:

  1. A word becomes empty string, or
  2. 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(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

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[];
int main()
{
int n;
while(cin>>n)
{
if(n==)
break;
for(int i=;i<n;i++)
cin>>s[i];
int flag=;
int flag2=;
if(n!=)
while()
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(i==j)
continue;
for(int k=;k<s[i].size();k++)
{
if(s[i][k]!='(')
break;
if(k==s[i].size()-)
{
flag2=;
break;
}
}
if(s[i]==s[j])
{
flag2=;
break;
}
}
}
if(flag2==)
break;
for(int i=;i<n;i++)
{
s[i][flag]='(';
}
flag++;
}
flag--;
if(flag<)
flag=;
cout<<flag<<endl; }
return ;
}

最新文章

  1. [Erlang 0112] Elixir Protocols
  2. 视图控制器的View整体上移问题
  3. EF:split your EDMX file into multiple diagrams
  4. windows下关闭进程
  5. mysql多实例安装脚本
  6. php 操作mongodb
  7. Android实例-MediaPlayer播放音乐和视频(XE8+小米2)
  8. hdoj 2524 矩形A + B【递推】
  9. 转:C# 定时任务实现
  10. android学习3——长宽的单位问题dp,px,dpi
  11. [UWP]了解模板化控件(5.2):UserControl vs. TemplatedControl
  12. mvc一对多模型表单的快速构建
  13. 软件测试人员在工作中如何运用Linux
  14. VIM编辑器操作命令积累
  15. mysql_config not found和error: command &#39;gcc&#39; failed with exit status 1
  16. shiro框架的UsernamePasswordToken与对应Realm中的AuthenticationToken的一点比较
  17. 2018阿里云短信发送DEMO接入简单实例
  18. 数据存储之属性列表Plist
  19. 5款替代微软Visio的开源免费软件(转)
  20. caanimationgroup与CATransaction的区别

热门文章

  1. 安装Visual Studio Scrum 1.0过程模板
  2. 如何提高单片机Flash的擦写次数
  3. 003_Mac挂载NTFS移动硬盘读取VMware虚拟机文件
  4. 自定义ProgressBar的加载效果
  5. C# TimeSpan获取 年月
  6. linux文件处理
  7. Java与redis交互、Jedis连接池JedisPool
  8. CSS — 贝塞尔曲线(cubic-bezier)
  9. 批处理命令篇--配置免安装mysql
  10. 安装配置SVN