第一届山东省ACM——Phone Number(java)
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
Sample Output
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)的更多相关文章
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- 第七届山东省ACM省赛
激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...
- 第十届山东省acm省赛补题(1)
今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...
- 2018年第九届山东省ACM省赛总结
去年打完区域赛之后,面对着两个队友都去找实习的情况,我自己对今年省赛还是有点慌的.不只一次的像我的队友说明自己很慌,但是老曹跟会长都说:“没事,慌啥!”前几场训练赛因为老曹跟秋洁有面试有时候只能一个人 ...
随机推荐
- android 设颜色透明值
如:把 <color name="line_gray_tran">#8d8d8d</color> 要设70%的透明值 计算方法:255*0.75=19 ...
- [jquery]if条件句
//写个网页用了多门语言,脑袋转不过来亚! //代码: if(){} else if(){} else {}
- Apache服务停止:信号灯超时时间已到,指定的网络名不再可用
环境说明:Apache2.4.10,Windows Server 2008 R2 问题说明: apache服务用于下载文件,但是在运行一段时间后,突然挂了. 其错误提示如下所示: [error] (7 ...
- Apache:如何访问共享目录
环境说明:Apache的版本是2.4.10,共享目录有两种情况,一种是windows server的目录共享,还有一种是linux的NAS.无论访问哪一种共享目录,都需要用户名和密码. 问题说明:如何 ...
- hdu2848 Visible Trees (容斥原理)
题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...
- [No00009F]CMD在执行命令时的中断快捷键
有两种: Ctrl+C:完全中断.类似于C语言在while循环中的Break: Ctrl+Break(Pause键):单步中断.类似于C语言在while循环中的Continue:
- 克隆虚机网卡出现 Device eth0 does not seem to be present, delaying initialization 错误
错误原因 克隆的Linux系统在新的机器上运行,新服务器网卡物理地址已经改变.而/etc/udev/rules.d/70-persistent-net.rules这个文件确定了网卡和MAC地址的 ...
- [LeetCode] Ugly Number II 丑陋数之二
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- Ext动态加载Toolbar
在使用Ext的GridPanel时候,有时候需要面板不用重新加载而去更新Store或者Toolbar,Store的方法有很多,例如官方api给我们提供的Store.load(),Store.reLoa ...
- Centos 7 使用jenkins 打包android项目
1.配置java环境 在sun官网下载,解压后放入/usr/java下,并配置环境变量如 vi /etc/profile 在最底部加入如下配置(注:添加环境变量,都是在文件最底部添加) J ...