hdu 1181

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Scanner;
public class Main
{
	static ArrayList<String> a=new ArrayList<String>();
	static Queue<String> b=new ArrayDeque<String>();
	public static void main(String[] args){
	     Scanner input=new Scanner(System.in);
		while(input.hasNext()){
			   String s;
			   while(!(s=input.next()).equals("0")){
			       if(s.charAt(0)=='b'){
				      b.add(s);
				   }
			       else
					  a.add(s);
			   }
			   System.out.println(F());
			   a.clear();
			   b.clear();
			}
	}
	private static String F(){
	    while(!b.isEmpty()){
		    String s=b.poll();
			char ch=s.charAt(s.length()-1);
			if(ch=='m')
				return "Yes.";
			for(int i=0;i<a.size();){
			    if(a.get(i).charAt(0)==ch){
				   b.add(a.remove(i));
				}
				else
					i++;
			}
		}
		return "No.";
	}
}

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181


你可能感兴趣的:(hdu 1181)