Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

最后输出有一个空行是可以的啦。。第一次用JAVA写出这么快的程序。。庆祝下

Posted by yzhw at 2009-03-01 16:39:57 on Problem 1053
import java.util.*;
import java.io.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		while(true)
		{
			String data[]=new String[13];
			data[1]=in.readLine();
			if(data[1]==null) break;
			TreeSet refer1=new TreeSet();
			TreeSet refer2=new TreeSet();
			TreeSet refer3=new TreeSet();
			TreeSet refer4=new TreeSet();
			
			for(int i=2;i<=12;i++) data[i]=in.readLine();
			String temp[]=new String[4];
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(0)==data[i].charAt(0))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(0)==data[i].charAt(0))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer1.add(res);
							}
						}
					}
				}
			}
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(0)!=data[i].charAt(0))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(0)!=data[i].charAt(0)&&data[k].charAt(0)!=data[j].charAt(0))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer1.add(res);
							}
						}
					}
				}
			}
			//----------------------------------------------------------
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(1)==data[i].charAt(1))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(1)==data[i].charAt(1))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer2.add(res);
							}
						}
					}
				}
			}
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(1)!=data[i].charAt(1))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(1)!=data[i].charAt(1)&&data[k].charAt(1)!=data[j].charAt(1))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer2.add(res);
							}
						}
					}
				}
			}
			//-----------------------------------------------------------------------------
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(2)==data[i].charAt(2))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(2)==data[i].charAt(2))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer3.add(res);
							}
						}
					}
				}
			}
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(2)!=data[i].charAt(2))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(2)!=data[i].charAt(2)&&data[k].charAt(2)!=data[j].charAt(2))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer3.add(res);
							}
						}
					}
				}
			}
			//------------------------------------------------------------------------------------
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(3)==data[i].charAt(3))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(3)==data[i].charAt(3))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer4.add(res);
							}
						}
					}
				}
			}
			for(int i=1;i<=12;i++)
			{
				temp[1]=data[i];
				for(int j=i+1;j<=12;j++)
				{
					if(data[j].charAt(3)!=data[i].charAt(3))
					{
						temp[2]=data[j];
						for(int k=j+1;k<=12;k++)
						{
							if(data[k].charAt(3)!=data[i].charAt(3)&&data[k].charAt(3)!=data[j].charAt(3))
							{
								temp[3]=data[k];
								String res=temp[1]+temp[2]+temp[3];
								refer4.add(res);
							}
						}
					}
				}
			}
			//----------------------------------------------------------------------------
			Iterator p=refer1.iterator();
			System.out.print("CARDS: ");
			for(int i=1;i<=12;i++) System.out.print(" "+data[i]);
			System.out.println();
			System.out.print("SETS:   ");
			int c=0;
			while(p.hasNext())
			{
				String res=(String)p.next();
				if(refer2.contains(res)&&refer3.contains(res)&&refer4.contains(res))
				{
					c++;
					if(c==1) System.out.print(c+". ");
					else System.out.print("        "+c+". ");
					System.out.print(" "+res.substring(0, 4));
					System.out.print(" "+res.substring(4, 8));
					System.out.print(" "+res.substring(8,12));
					System.out.println();
				}
			}
			if(c==0) 
			{
				System.out.print("*** None Found ***");
				System.out.println();
			}
			System.out.println();
			in.readLine();
		}

	}

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator