cometoj——[Contest #12]Competitive Problem Setting

题目描述

Chiaki经常给各种比赛出题,每场比赛需要的题目数从3到25不等,因此对题目的管理显得非常重要。

为了方便管理,Chiaki决定给每个题目取一个只有3个字符的编码。对于一个标题为ss的题目,它的编码是ss长度为3的前缀。

现在给出Chiaki出的nn个题的标题,求出这n个题的编码是否互不相同。

输入描述

输入有多组数据。第一行有一个整数T,表示测试数据组数。然后对于每组数据:

第一行包含一个整数n 3≤n≤25),表示题目数目。

接下来nn行,每行包含一个字符串s_i (3≤s i≤25),表示第i个题目的标题。保证s_i仅由英语小写字母组成。

保证所有数据中nn的和不超过1000。

输出描述

对于每组数据,如果这n个题目的编码互不相同,输出Yes,否则输出No。

样例输入 1

2
23
rectangles
tables
knight
dice
pawn
drilling
thewaytobytemountain
stamps
byteanteantowns
circulargame
permutation
quasitemplate
cakes
diamond
cards
fishes
chess
typetwodebruijnsequences
fibonaccimachine
colouring
programmingcontest
watchmen
tram
3
abcd
abce
cccd
样例输出 1

Yes
No
样例解释 1

对于第1个样例,所有长度为3的前缀都互不相同,所以输出是Yes。

对于第2个样例,前两个题目的前缀都是abc,所以输出是No。


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class c1876 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputReader in = new InputReader(System.in);
		int T = in.nextInt();
		for(int i=0;i<T;i++)
		{
			boolean judge = true;
			int n = in.nextInt();
			List<String> list = new ArrayList();
			int j=0;
			for(j=0;j<n;j++)
			{
				String s = in.next();
				if(list.indexOf(s.substring(0,3))==-1)
				{
					list.add(s.substring(0,3));
				}
				else
				{
					judge = false;
					System.out.println("No");
					for(int k=j+1;k<n;k++)
					{
						s = in.next();
					}
					break;
				}
			}
			if(judge)
				System.out.println("Yes");
		}
		
	}
	static class InputReader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream),32768);
			tokenizer = null;
		}
		public String next() {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			}
			catch(IOException e){
				throw new RuntimeException(e);
			}
			return tokenizer.nextToken();
		}
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章