| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
麻烦大牛看看我哪错了,真的崩溃了import java.util.Scanner;
public class Main{
static boolean[][] map;
static boolean[] judge;
static char[] tot;
static int n,m;
static Scanner in;
static void get()
{
for(int i=0;i<m;i++)
{
String s=in.next();
int a=s.charAt(0)-'A',b=s.charAt(2)-'A';
if(s.charAt(1)=='>')
{
int temp=a;
a=b;
b=temp;
}
map[a][b]=true;
for(int j=0;j<n;j++)
for(int t1=0;t1<n;t1++)
for(int t2=0;t2<n;t2++)
if(map[t1][j]&&map[j][t2])
map[t1][t2]=true;
for(int j=0;j<n;j++)
{
if(map[j][j])
{
System.out.println("Inconsistency found after "+(i+1)+" relations.");
for(int tt=i+1;tt<m;tt++)
in.next();
return;
}
int count=0;
for(int k=0;k<n;k++)
if(map[j][k])
count++;
judge[count]=true;
tot[count]=(char)('A'+j);
}
int j;
for(j=0;judge[j];j++);
if(j>=n)
{
System.out.print("Sorted sequence determined after "+(i+1)+" relations: ");
for(j=n-1;j>-1;j--)
System.out.print(tot[j]);
System.out.println(".");
for(int tt=i+1;tt<m;tt++)
in.next();
return;
}
}
System.out.println("Sorted sequence cannot be determined.");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
in=new Scanner(System.in);
while(true)
{
n=in.nextInt();
m=in.nextInt();
if(n==0&&m==0)
return;
map=new boolean[26][26];
judge=new boolean[27];
tot=new char[26];
get();
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator