Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
Phone Number
Time Limit: 1000MS Memory limit: 65536K
题目描述
know that if a phone number A is another phone number B’s prefix, B is not able to be called. For an example, A is 123 while B is 12345, after pressing 123, we call A, and not able to call B.
Given
N phone numbers, your task is to find whether there exits two numbers A and B that A is B’s prefix.
输入
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 phone numbers.
The
last case is followed by a line containing one zero.
输出
each test case, if there exits a phone number that cannot be called, print “NO”, otherwise print “YES” instead.
示例输入
2
012
012345
2
12
012345
0
示例输出
NO
YES
#include<iostream>
#include<string>
using namespace std;
string a[1005],k; int b[1005];
int main()
{
int n,i,j,p,s;
while(cin>>n&&n)
{
s=0;
for(i=0;i<n;i++)
cin>>a[i]; for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
{if(a[j]>a[j+1])
{k=a[j];
a[j]=a[j+1];
a[j+1]=k;}}
//for(i=0;i<n;i++)
//cout<<a[i]<<endl;
for(i=0;i<n;i++)
b[i]=a[i].size();
for(i=0;i<n-1;i++)
{p=b[i]<b[i+1]?b[i]:b[i+1];
for(j=0;j<p;j++)
if(a[i][j]!=a[i+1][j]) break;
else if(j==p-1)
s=1;
}
// for(i=0;i<n-1;i++)
// if(a[i]==a[i+1])
// s=2;
if(s==1)
cout<<"NO"<<endl;
else
if(s==0)
cout<<"YES"<<endl; } return 0;
}
Phone Number 2010年山东省第一届ACM大学生程序设计竞赛的更多相关文章
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)
题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...
- sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散
先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...
- 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)
题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...
- [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers
Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
随机推荐
- POJ2112_Optimal Milking(网洛流最大流Dinic+最短路Flody+二分)
解题报告 农场有k个挤奶机和c头牛,每头牛到每一台挤奶机距离不一样,每台挤奶机每天最多挤m头牛的奶. 寻找一个方案,安排每头牛到某一挤奶机挤奶,使得c头牛须要走的全部路程中的最大路程的最小值. 要使每 ...
- HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...
- Cordova/Phonegap 升级至 2.8.1
相关链接 Apache Cordova 项目首页: http://cordova.apache.org/ Apache Cordova 历史版本列表: http://archive.apache.or ...
- java自己主动打开包装盒很容易导致两个误区
从J2SE 5.0开始提供基本数据类型的自己主动装箱(autoboxing).拆箱(unboxing)功能. 何为自己主动装箱: 当我们创建一个Integer对象时,却能够这样: Integer i ...
- Extjs4 RowEditing 的使用和更新方法
如何灵活快速的掌握RowEditing组件的应用,应大家的要求,今天给大家具体讲下该组件的使用. 1.创建 var rowEditing = Ext.create('Ext.grid.plugin.R ...
- URAL1113(数学)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1113 根据样例分析: 1.沙漠只有500公里或者更短,这时很简单,一次搞定. 2.沙漠6 ...
- js封装好的模仿qq消息弹窗代码
在我们的日常开发中,或者生活中.常常须要用到弹出窗.这里我们就用js模拟一下qq消息一样的弹出窗. 直接贴代码: <!DOCTYPE html PUBLIC "-//W3C//DTD ...
- VS调试技巧之附加进程
用过VS一段时间的程序猿们相信都有过这种调试经历:每次按下F5进行断点调试时,都要等待好长时间:先让解决方式编译通过,然后启动VS自带的简版IIS作为server启动,进而开启浏览器,最后进行对应的操 ...
- as 的妙用
个人理解:as跟is is 相当于判断里的“==” 是与否 if(e.OriginalSource is Button) as 一般用来转换另一种object e.OriginalSource as ...
- 每日算法之三十三:Trapping Rain Water
这是一个非常有意思的问题,求解最大容积问题,值得动脑筋想一想. 原题例如以下: Given n non-negative integers representing an elevation map ...