UVA_489


题目描述:点击打开链接


/*
	思路:由于子串一个字符可以翻起主串所有相同字符,
	例如:主串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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值