3801. String LD
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
注意点:
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的更多相关文章
- UVALive 4423 String LD 暴力
A - String LD Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Stat ...
- [Java] 日期的简单处理
package test.date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.u ...
- Delphi Waring 的信息
Display PreferencesWarning messages (Delphi)Go Up to Delphi Compiler Directives (List) Index TypeSwi ...
- Android使用GridView实现日历功能(详细代码)
代码有点多,发个图先: 如果懒得往下看的,可以直接下载源码吧(0分的),最近一直有人要,由于时间太久了,懒得找出来整理,今天又看到有人要,正好没事就整理了一下 http://download.csdn ...
- 2015 UESTC Winter Training #4【Regionals 2008 :: Asia - Tehran】
2015 UESTC Winter Training #4 Regionals 2008 :: Asia - Tehran 比赛开始时电脑死活也连不上WIFI,导致花了近1个小时才解决_(:зゝ∠)_ ...
- 基于Google Earth Engine的全国地表温度反演
国内研究landsat8温度反演的人员很多,但是现有算法一般都是一景为例子,进行开展. 这有一个局限性,当研究的尺度很大时,就需要比较大的运算量了,例如全省温度,全国温度,全球温度,当然大家可能会说, ...
- Java 实现输入公历日期输出农历日期、生肖、天干地支、节日、节气等信息
最近的工作中客户要求前台页面展示日历,日历内容包括:农历年月日日.公历年月日.生肖.天干地支.农历节日.公历节日.24节气等信息,之前在网上查找资料关于Java实现方面的文章不少,但是大多数针对节气. ...
- LD算法获取字符串相似度
一个如何识别相似语句的问题,于是上网找了找,一个叫Levenshtein Distance的算法比较简单,就写了段代码实现了一下,效果还不错. 这个算法是一个俄国人Lvenshtein提出的,用于计算 ...
- Hdu 4681 2013 Multi-University Training Contest 8 String
带跨越式的LCS,同样是在朴素的LCS上加入一种跨越一段的转移,这样我们要预处理出跨越一段给定串的转移函数. 这个题同样可以正反两边LCS做 呆马: #include <iostream> ...
随机推荐
- 二叉树学习笔记之经典平衡二叉树(AVL树)
二叉查找树(BSTree)中进行查找.插入和删除操作的时间复杂度都是O(h),其中h为树的高度.BST的高度直接影响到操作实现的性能,最坏情况下,二叉查找树会退化成一个单链表,比如插入的节点序列本身就 ...
- 在SSIS包中的事务处理
在处理SSIS包的数据ETL操作过程中,我们经常遇到的一个问题就是一系列步骤在运行的过程中,如果中间的一个步骤失败了,那么我们就需要清理前面已经运行过的步骤所产生的数据或者结果,这往往是一个很头疼的过 ...
- Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏
效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- Angular JS [Draft]
AngularJS应用是完全运行在客户端的应用.没有后端的支持,我们只能展示随页面一起加载进来的数据.AngularJS提供了几种方式从服务器端获取数据. $http服务 $http 封装了浏览器原生 ...
- 数据结构之图 Part2 - 2
邻接表 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...
- ASP.NET 5探险(5):利用AzureAD实现单点登录
题记:在ASP.NET 5中虽然继续可以沿用ASP.NET Identity来做验证授权,不过也可以很容易集成支持标准协议的第三方服务,比如Azure Active Directory. 其实,在AS ...
- poj 2115 Looooops
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23637 Accepted: 6528 Descr ...
- js String对象
字符串(String) 字符串(String)使用长度属性length来计算字符串的长度: 在字符串中查找字符串 字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置: 实例 ...
- ASP.NET中的GridView自带的编辑更新功能
string ConStr = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].Connec ...
- Android 插件化 动态升级
最新内容请见原文:Android 插件化 动态升级 不少朋友私信以及 Android开源交流几个 QQ 群 中都问到这个问题,这里简单介绍下 1.作用 大多数朋友开始接触这个问题是因为 App 爆棚了 ...