Description

We 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

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 phone numbers.

The last case is followed by a line containing one zero.

Output

For each test case, if there exits a phone number that cannot be called, print “NO”, otherwise print “YES” instead.

Sample Input

2 012 012345 2 12 012345 0

Sample Output

NO YES

HINT

 

Source

山东第一届省赛

题目链接:http://acm.upc.edu.cn/problem.php?id=1928



字符串匹配(intdexOf(String str)),O(n2)

代码:

import java.util.Scanner;
public class Main{
public static String s[];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int len[];
while(sc.hasNextInt()){
int n=sc.nextInt();
if(n<=0)
break;
s=new String[n];
len=new int[n];
for(int i=0;i<n;i++){
s[i]=sc.next();
len[i]=s[i].length();
}
for(int i=0;i<n-1;i++){
int k=len[i];
int temp=i;int d=0;
String ss;
for(int j=i+1;j<n;j++){
if(k>len[j]){
k=len[j];
temp=j;
}
}
if(temp>i){
d=len[i];len[i]=len[temp];len[temp]=d;
ss=s[i];s[i]=s[temp];s[temp]=ss;
}
}
int ddd=0;
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
int dd=s[j].indexOf(s[i]);
if(dd==0){
System.out.println("NO");
ddd=1;
break;
}
}
if(ddd==1)
break;
}
if(ddd==0)
System.out.println("YES");
}
}
}

第一届山东省ACM——Phone Number(java)的更多相关文章

  1. 第一届山东省ACM——Balloons(java)

    Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...

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

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

  3. sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)

    Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...

  4. sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  5. sdut 2154:Shopping(第一届山东省省赛原题,水题)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  6. sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

  7. 第七届山东省ACM省赛

    激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...

  8. 第十届山东省acm省赛补题(1)

    今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...

  9. 2018年第九届山东省ACM省赛总结

    去年打完区域赛之后,面对着两个队友都去找实习的情况,我自己对今年省赛还是有点慌的.不只一次的像我的队友说明自己很慌,但是老曹跟会长都说:“没事,慌啥!”前几场训练赛因为老曹跟秋洁有面试有时候只能一个人 ...

随机推荐

  1. windows下redis安装

    最近因公司项目原因,去了趟昆明出差,其中第一次接触安装redis,配置sentinel,学习到不少,但也都是皮毛而已,本随笔记下所学知识. 1.首先介绍下redis,来源自百度百科 redis是一个k ...

  2. Jmeter实现登录bugfree、新建bug、解决bug脚本(抓包工具实现)

    环境 Chrome jmeter3.1 fiddler4 win7 32位 Linux CentOs6.4 bugfree3.0.1 链接:http://pan.baidu.com/s/1gfHpbp ...

  3. jsp九大内置对象

    application例如用于计算网站访问量时可用到.

  4. Statement对象的executeUpdate返回信息

    int num = sta.executeUpdate(String sql);返回的是我们平时操作数据库客户端时控制台显示的影响行数

  5. 使用 iscroll 实现焦点图无限循环

    现在大家应该都看到过焦点图轮播的效果,这个效果是什么样我就不截图了.昨天做练习,练习要求是使用iscroll实现焦点图的无限循环滚动,并且当手指触摸焦点图后,停止焦点图的循环滚动.第一次接触iscro ...

  6. [LeetCode] Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  7. NPOI操作EXCEL(四)——反射机制批量导出excel文件

    前面我们已经实现了反射机制进行excel表格数据的解析,既然有上传就得有下载,我们再来写一个通用的导出方法,利用反射机制实现对系统所有数据列表的筛选结果导出excel功能. 我们来构想一下这样一个画面 ...

  8. IT培训行业揭秘(五)

    前面说了一大堆,简单揭露了一些目前培训行业鱼龙混在的情况,那么今天我就站在一个即将毕业的大学生角度来谈谈如何选择一个靠谱的培训机构. 你即将大学毕业了,在大学里面浑浑噩噩的混了几年,马上就要离开校园, ...

  9. HTTP服务器(2)

    导语 重定向器是特殊用途的HTTP服务器的另一个简单而有用的应用程序.它的作用就是将用户从一个WEB网站重定向到另外一个网站.下面是一个简单的例子,程序沿用上一个SingleHttpServer代码. ...

  10. 用vue.js学习es6(三):数组、对象和函数的解构

    一.数组的解构: 以前的方式: var arr = [1,2,3]; console.log(arr[0]); //1 console.log(arr[1]); //2 现在的方式: var [a,b ...