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> ... 
随机推荐
- C#集合类型
			using System; using System.Collections; using System.Collections.Generic; namespace codeTest { class ... 
- Java集合源码学习(一)集合框架概览
			>>集合框架 Java集合框架包含了大部分Java开发中用到的数据结构,主要包括List列表.Set集合.Map映射.迭代器(Iterator.Enumeration).工具类(Array ... 
- JAVA基础学习之流的简述及演示案例、用缓冲区方法buffer读写文件、File类对象的使用、Serializable标记接口(6)
			1.流的简述及演示案例输入流和输出流相对于内存设备而言.将外设中的数据读取到内存中:输入将内存的数写入到外设中:输出.字符流的由来:其实就是:字节流读取文字字节数据后,不直接操作而是先查指定的编码表. ... 
- attributeError:'module' object  has no attribute ** 解决办法
			写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ... 
- Jmeter在restful风格接口测试中的应用
			1.如何下载安装 官网下载,一个压缩包apache-jmeter-3.0.zip,解压即可,打开bin目录下jmeter.bat即可打开软件. 2.熟悉界面 3.实际案例 测试restful风格接口 ... 
- 吐个槽,对VB6.0 还有VBS 说ByeBye
			往事不堪回首,折腾了个把月的老系统,心中郁结,不吐不快.系统架构是ASP +VBS +VB6.0 + SQL Server2000, 第一个版本开发完成大概是在2000年.基本是处于交接无力,看代码就 ... 
- php判断访问的当前设备是手机还是电脑
			<?php function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AG ... 
- [JAVA] IOException: Invalid byte 2 of 2-byte UTF-8 sequence(解决办法)
			日志打印不全,后台只打印出出标题的异常信息: 先前的日志打印信息:log.debug(e.getMessage()); 后面改成了日志打印信息:log.debug(e); log.debug(e.ge ... 
- 怎样打开64位 Ubuntu 的32位支持功能?
			转自:http://jingyan.baidu.com/article/7082dc1c539c15e40a89bd3e.html 大多数使用基于 Ubuntu/Debian 的发行版的人都更倾向于选 ... 
- 基于socket、多线程的客户端服务器端聊天程序
			服务器端: using System; using System.Windows.Forms; using System.Net.Sockets; using System.Net;//IPAddre ... 
