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. HTML CSS微信CSS显示一些总结

    微信显示网页是调用腾讯自带的浏览器内核,由于腾讯浏览器内核对css展示效果没有谷歌浏览器好,导致用谷歌浏览器写好的网页,放到微信页面之后,显示的效果就发生变化,所以调整css样式显得那么吃力: 1. ...

  2. 攻城狮在路上(壹) Hibernate(十一)--- 映射实体关联关系

    本文以Customer和Address类的关系为例说明一对一关联映射:以Category和Item类的关系说明多对多关联关系.一.映射一对一关联: 分两种情况:按照外键映射和按照主键映射.这两种方式的 ...

  3. angular入门

    angular入门 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&q ...

  4. WPF MVVM模式下实现ListView下拉显示更多内容

    在手机App中,如果有一个展示信息的列表,通常会展示很少一部分,当用户滑动到列表底部时,再加载更多内容.这样有两个好处,提高程序性能,减少网络流量.这篇博客中,将介绍如何在WPF ListView中实 ...

  5. 跟着鸟哥学Linux系列笔记2-第10章VIM学习

    跟着鸟哥学Linux系列笔记0-扫盲之概念 跟着鸟哥学Linux系列笔记0-如何解决问题 跟着鸟哥学Linux系列笔记1 常用的文本编辑器:Emacs, pico, nano, joe, vim VI ...

  6. DWZ分页、排序失效小结

    1. 在视图文件中与分页相关的代码段 <form id="pagerForm" method="post" action="w_list.htm ...

  7. loj 1044(dp+记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...

  8. MFC 丢失MSVCR120D.dll 丢失mfc120ud.dll

  9. Input对象的type类型

    Input表示Form表单中的一种输入对象,其又随Type类型的不同而分文本输入框,密码输入框,单选/复选框,提交/重置按钮等,下面一一介绍. 1,type=text        输入类型是text ...

  10. 【java 断点续传】

    模拟 断点续传 首先,先读取word文件的 一部分 package com.sxd.readLines; import java.io.File; import java.io.FileInputSt ...