Sdut 2151 Phone Numbers (山东省ACM第一届省赛题 A)
题目描述
We know thatif a phone number A is another phone number B’s prefix, B is not able to becalled. For an example, A is 123 while B is 12345, after pressing 123, we callA, and not able to call B.
Given N phone numbers, your task is to find whether there exits two numbers Aand B that A is B’sprefix.
输入
The input consists of several test cases.
The first line of input in each test case contains one integer N (0<N<1001),represent the number of phone numbers.
The next line contains N integers, describing the phonenumbers.
The last case is followed by a line containing one zero.
输出
For each test case, if there exits a phone number thatcannot be called, print “NO”, otherwise print “YES” instead.
示例输入
2
012
012345
2
12
012345
0
示例输出
NO
YES
/*********************
N个字符串中如果有一个是另外一个的前缀,则输出NO,否则输出YES。
O(n^2)的循环,
*********************/
Code:
#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str[1005][1005];
char s[1005];
int n,i,j,li,lj;
bool leaf;
while(scanf("%d",&n)&&n)
{
leaf = false;
li = lj = 0;
for(i = 0;i<n;i++)
cin>>str[i];
for(i = 0;i<n;i++)
{
li = strlen(str[i]);
for(j = 0;j<n;j++)
{
lj = strlen(str[j]);
if(i==j||li>lj)//自己不和自己比较,str[j] 长度比str[i]短的话肯定不是前缀。
continue;
strncpy(s,str[j],li);
s[li] = '\0';
if(strcmp(s,str[i])==0)// 发现前缀则跳出循环
{
leaf = true;
break;
}
}
if(leaf)
break;
}
if(leaf)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
Sdut 2151 Phone Numbers (山东省ACM第一届省赛题 A)的更多相关文章
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
题目描述 We know thatIvan gives Saya three problems to solve (Problem F), and this is the firstproblem. ...
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
Binomial Coeffcients TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
Crack Mathmen TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take security ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- Greatest Number 山东省第一届省赛
Greatest Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya likes math, because ...
- 山东第一届省赛1001 Phone Number(字典树)
Phone Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 We know that if a phone numb ...
- 山东省第六届省赛 BIGZHUGOD and His Friends II(赛瓦定理)
Description BIGZHUGOD and his three friends are playing a game in a triangle ground. The number of B ...
- 山东省第七届省赛 D题:Swiss-system tournament(归并排序)
Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...
随机推荐
- Javascript 查找字符串中出现最多的字符和出现的次数
<script type="text/javascript"> //查找字符串中出现最多的字符和出现的次数 var str = 'Thatwheneying its o ...
- replace empty char with new string,unsafe method和native implementation的性能比较
1: class Program 2: { 3: static void Main(string[] args) 4: { 5: string s = File.ReadAllText(@" ...
- ubuntukylin(64bit)安装推荐
UbuntuKylin是Ubuntu社区中面向中文用户的Ubuntu衍生版本,与麒麟系统没有关系.它是由工信部软件.集成电路促进中心(CSIP).国防科技大学(NUDT)与国际著名开源社区UBUNTU ...
- Java程序员25个必备的Eclipse插件
原文:http://www.fromdev.com/2012/01/25-best-free-eclipse-plug-ins-for-java.html "工欲善其事, 必先利器" ...
- hyperVisor
当前主要的hyperVisors:VMware vSphere.微软Hyper-V.Citrix XenServer .IBM PowerVM.Red Hat Enterprise Virtuliza ...
- c语言结构体中的冒号的用法
结构体中常见的冒号的用法是表示位域. 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省 ...
- ReactiveCocoa框架学习2
昨天内容回顾 信号类:表示有数据产生,信号类不发送数据 注意:不同的信号,订阅方式不同 RACSignal 创建RACDynamicSignal信号 -> didSubscribe(block) ...
- ASP.NET- 播放视频代码
在网上找的,还不错,支持很多格式.只需要在页面放个lable,建一个放视频文件的文件夹movie,加入代码: protected void Page_Load(object sender, Event ...
- Java整型与字符串相互转换(转)
1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([S ...
- [置顶] RGB颜色查询对照表
因为兼容性问题,色阶板功能只能在IE浏览器中运行 RGB颜色对照表 #FFFFFF #FFFFF0 #FFFFE0 #FFFF00 #FFFAFA #FFFAF0 #FFF ...