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 (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

注意点:

1、字符串str和计数器num_count一定记得每次之后清除数据。

      for(i=0;i<n;i++)//清空字符串数组
        memset(str[i],0,sizeof(str[i]));
      num_count = -1;

2、大数组要开在main函数之外。

代码:

 #include <stdio.h>
#include <string.h> char str[][]; void stringld(int x);
int is_nullorsame(int x); int main(void)
{
int n=,i=;
int num_count=-;
while(scanf("%d",&n) != EOF){
if(n == ) break;
for(i=;i<n;i++)
scanf("%s",str[i]);
//处理
while(is_nullorsame(n) == ){
num_count++;
stringld(n);
}
printf("%d\n",num_count);
for(i=;i<n;i++)//清空字符串数组
memset(str[i],,sizeof(str[i]));
num_count = -;
} //system("PAUSE");
return ;
} void stringld(int x)
{
int i,j;
for(i=;i<x;i++){
for(j=;j<strlen(str[i]);j++)
str[i][j] = str[i][j+];
}
} int is_nullorsame(int x)
{
int i,j;
//先判是否为空
for(i=;i<x;i++)
if(strlen(str[i]) == ) return ;
//判断相同
for(i=;i<x;i++)
for(j=i+;j<x;j++)
if(strcmp(str[i],str[j]) == ) return ;
return ;
}

3801. String LD的更多相关文章

  1. UVALive 4423 String LD 暴力

    A - String LD Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...

  2. [Java] 日期的简单处理

    package test.date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.u ...

  3. Delphi Waring 的信息

    Display PreferencesWarning messages (Delphi)Go Up to Delphi Compiler Directives (List) Index TypeSwi ...

  4. Android使用GridView实现日历功能(详细代码)

    代码有点多,发个图先: 如果懒得往下看的,可以直接下载源码吧(0分的),最近一直有人要,由于时间太久了,懒得找出来整理,今天又看到有人要,正好没事就整理了一下 http://download.csdn ...

  5. 2015 UESTC Winter Training #4【Regionals 2008 :: Asia - Tehran】

    2015 UESTC Winter Training #4 Regionals 2008 :: Asia - Tehran 比赛开始时电脑死活也连不上WIFI,导致花了近1个小时才解决_(:зゝ∠)_ ...

  6. 基于Google Earth Engine的全国地表温度反演

    国内研究landsat8温度反演的人员很多,但是现有算法一般都是一景为例子,进行开展. 这有一个局限性,当研究的尺度很大时,就需要比较大的运算量了,例如全省温度,全国温度,全球温度,当然大家可能会说, ...

  7. Java 实现输入公历日期输出农历日期、生肖、天干地支、节日、节气等信息

    最近的工作中客户要求前台页面展示日历,日历内容包括:农历年月日日.公历年月日.生肖.天干地支.农历节日.公历节日.24节气等信息,之前在网上查找资料关于Java实现方面的文章不少,但是大多数针对节气. ...

  8. LD算法获取字符串相似度

    一个如何识别相似语句的问题,于是上网找了找,一个叫Levenshtein Distance的算法比较简单,就写了段代码实现了一下,效果还不错. 这个算法是一个俄国人Lvenshtein提出的,用于计算 ...

  9. Hdu 4681 2013 Multi-University Training Contest 8 String

    带跨越式的LCS,同样是在朴素的LCS上加入一种跨越一段的转移,这样我们要预处理出跨越一段给定串的转移函数. 这个题同样可以正反两边LCS做 呆马: #include <iostream> ...

随机推荐

  1. Oracle Redhat5.5

    http://blog.csdn.net/yakson/article/details/9012129 http://www.cnblogs.com/cnmarkao/p/3670153.html h ...

  2. Linux下Vi/Vim使用笔记

    启动和关闭vim vi 打开 Vi/Vim 打开 Vi/Vim 并加载文件 <file> vi <file> vim编辑器的三种模式:一般模式.编辑模式和命令行模式在一般模式中 ...

  3. Linux性能分析工具的安装和使用

    转自:http://blog.chinaunix.net/uid-26488891-id-3118279.html Normal 0 7.8 磅 0 2 false false false EN-US ...

  4. JavaWeb学习之Path总结、ServletContext、ServletResponse、ServletRequest(3)

    1.Path总结 1.java项目 1 File file = new File(""); file.getAbsolutePath(); * 使用java命令,输出路径是,当前j ...

  5. HTML - DOCTYPE

    HTML - DOCTYPE HTML 5 doctype <!DOCTYPE html> HTML4.01 Based on SGML. so the browser need the ...

  6. IIS7报错

    错误内容:”未能加载文件或程序集“IWMS_Admin”或它的某一个依赖项.试图加载格式不正确的程“ 解决方法:进入IIS“应用程序池”,然后在右边列表中,选中当前网站所使用的程序池,打开右侧的“高级 ...

  7. WebRTC之带宽控制部分学习(1) ------基本demo的介绍

    转自:http://blog.csdn.net/u013160228/article/details/46392037 WebRTC的代码真是非常之大啊,下载以及编译了我好几天才搞完..... 可以看 ...

  8. 谈谈网站插入youtube视频播放

    最近需要在网页首页追加视频播放功能. 需要播放youtube视频.中间遇到一些波折.特来分享一下. 首先像网页添加视频文件我们通常够采用embed标签. 标签里可以设置很多的关键子.我们可以配置为fl ...

  9. Codeforces Round #355 (Div. 2)-A

    A. Vanya and Fence 题目连接:http://codeforces.com/contest/677/problem/A Vanya and his friends are walkin ...

  10. css整理-04 基本视觉格式化

    基本框 假定每一个元素都会生成一个火多个矩形框,为元素框 元素框中心有一个内容区,周围有内边距,边距和外边距 内容的背景会应用到内边距,外边距是透明的,可以看到父元素的背景 内边距不能是负值,外边距可 ...