题目描述

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)的更多相关文章

  1. ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)

    题目描述 We know thatIvan gives Saya three problems to solve (Problem F), and this is the firstproblem. ...

  2. Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)

    Binomial Coeffcients TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...

  3. Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

    Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Since mathmen take security ...

  4. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  5. sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)

    Ivan comes again! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...

  6. Greatest Number 山东省第一届省赛

    Greatest Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya likes math, because ...

  7. 山东第一届省赛1001 Phone Number(字典树)

    Phone Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We know that if a phone numb ...

  8. 山东省第六届省赛 BIGZHUGOD and His Friends II(赛瓦定理)

    Description BIGZHUGOD and his three friends are playing a game in a triangle ground. The number of B ...

  9. 山东省第七届省赛 D题:Swiss-system tournament(归并排序)

    Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...

随机推荐

  1. 洛谷1439 排列LCS问题

    洛谷1439 排列LCS问题 本题地址:http://www.luogu.org/problem/show?pid=1439 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输 ...

  2. MySQL WorkBench中文教程

    在网上找到了一份MySQL WorkBench的教程,点此可以下载Work Bench教程(原文),为了便于学习和交流,请朋友帮忙翻译成了中文,点此可以下载Work Bench教程(中文翻译版). 具 ...

  3. hdoj 4738 Caocao's Bridges【双连通分量求桥】

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

  5. 用jQuery实现优酷首页轮播图

    ▓▓▓▓▓▓ 大致介绍 看到了一个轮播图的思路,就想的自己动手实践一下,总体来说用jQuery实现起来简单多了 如果对代码中使用的方法有疑问,可以参考我的jQuery学习之路(持续更新),里面有讲解: ...

  6. 一、两种方式初始化Mybatis

    一.xml Configuration.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTY ...

  7. 【转】android Camera 中添加一种场景模式

    http://blog.csdn.net/fulinwsuafcie/article/details/8833652 首先,来了解一下什么是场景模式. 最简单的方法当然是google了,这里有一篇文章 ...

  8. 无法打开SQL Server的连接

       机房收费系统重构版的登陆敲了好几天了,总算把登陆窗口敲完了,代码调试的差点儿相同了,问题就处在数据库了.    SQL Server配置管理里的SQL  Server服务都启动了,可是还是报这个 ...

  9. 怎样查看MySql数据库物理文件存放位置

    想导出mysql中的数据库文件,死活找不到,网上说在配置文件中有路径,可是我打开我的配置文件,里边的代码全都是注释掉的,没有一句有用的.后来在某一论坛上找到解决方法了,记录下来. 使用如下命令: my ...

  10. FAQs: 我们可以在那里来为我的没有提升管理权限的应用程序存储用户数据?

    如果你正在写一个不需要管理员权限的应用程序,如写一个业务线应用(Line of Business,LOB),用户应用程序如游戏,你总是要把应用程序的数据写到一个标准用可以访问的目录.下面列出一些所推荐 ...