UVA_489

来源:互联网 发布:淘宝买汽车靠谱吗 编辑:程序博客网 时间:2024/04/30 06:36


题目描述:点击打开链接


/*思路:由于子串一个字符可以翻起主串所有相同字符,例如:主串book,子串字符o可以将主串中间的两个o翻起.所以将主串唯一化存储起来,在用子串字符判断便可. */import java.util.HashSet;import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner cin = new Scanner(System.in);while(cin.hasNext()){int n = cin.nextInt();if(n==-1)break;String strA=cin.next();String strB=cin.next();HashSet<Character> set = new HashSet<>();for(char ch:strA.toCharArray())set.add(ch);int cnt=0;boolean mark[]=new boolean[26];for(char ch:strB.toCharArray()){if(set.contains(ch)){set.remove(ch);if(set.isEmpty()){System.out.println("Round "+n);System.out.println("You win.");cnt=7;break;}}else if(!mark[ch-'a']){if(++cnt==7){System.out.println("Round "+n);System.out.println("You lose.");break;}mark[ch-'a']=true;}}if(cnt!=7){System.out.println("Round "+n);System.out.println("You chickened out.");}}}}





1 0