Pages

Sunday 16 December 2012

UVA - 12554 - A Special "Happy Birthday" Song!!!

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer("");
        String []happy={"Happy","birthday","to","you","Happy","birthday","to","you"
        ,"Happy","birthday","to","Rujia","Happy","birthday","to","you"};
        int cases=Integer.parseInt(br.readLine());
        Queue<String> qu=new LinkedList();
        for(int i=0;i<cases;i++){
           qu.add(br.readLine());
        }
        while (cases>0){
            for(int i=0;i<happy.length;i++){
                String temp=qu.remove();
                sb.append(temp).append(": ").append(happy[i]).append("\n");
                qu.add(temp);
            }
            cases-=happy.length;
        }
        System.out.print(sb);
    }
   
}

No comments:

Post a Comment