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. HTTP状态码(HTTP Status Code)

    一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 所有状态解释: 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 代码 说 ...

  2. 【原】pageResponse - 让H5适配移动设备全家(移动端适配)

    上一篇文章<为什么选择iPhone5的分辨率作为H5视觉稿尺寸>最后留下了问题:是否需要视觉设计师设计多套的视觉稿供给前端工程师做页面适配呢?按照自己以前的方法,通常会要求设计师设计2套的 ...

  3. Linux下的C Socket编程 -- 简介与client端的处理

    Linux下的C Socket编程(一) 介绍 Socket是进程间通信的方式之一,是进程间的通信.这里说的进程并不一定是在同一台机器上也有可能是通过网络连接的不同机器上.只要他们之间建立起了sock ...

  4. JAVA设计模式之3-抽象工厂模式

    书接上文,简单工厂模式解决的是可以枚举种类的类的问题,但是带来了高耦合的问题,并且对类系列繁多无从下手,那么我们想起了一种方法,那就是抽象类,建一个抽象工厂,抽象工厂里的方法都是根据系列类的差异区分出 ...

  5. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

  6. Spring + SpringMVC + Druid + MyBatis 给你一个灵活的后端解决方案

    生命不息,折腾不止. 折腾能遇到很多坑,填坑我理解为成长. 两个月前自己倒腾了一套用开源框架构建的 JavaWeb 后端解决方案. Spring + SpringMVC + Druid + JPA(H ...

  7. 时间格式转换—将后台返回的/Date(1448954018000)/格式转换为正常的时间格式

    用JS实现方法: function ChangeDateFormat(cellval) { )); < ? ) : date.getMonth() + ; ? " + date.get ...

  8. 关于#define for if(false);else for

    今日在看一个第三方代码时看到了#define for if(false);else for 这样的一种定义,不明白这样用法的目的,于是查了一下. 这是一个兼容vc6.0的用法,csdn上有这个问题的回 ...

  9. Java jdbc访问sqlserver,oracle数据库

    1.JDBC访问Oracle数据库 public class Jdbc_Oracle { // 静态代码块,只会执行一次,类似C#静态构造方法 static { try { // 加载数据库驱动一次 ...

  10. 【日常操作记录】Asp.Net Core 的一些基本操作或属性

    用于记录在项目中使用到的方法.属性.操作,持续更新中 静态文件的使用 在项目中静态文件的使用需要在Startup中的Configure方法中增加: //使用静态文件 app.UseStaticFile ...