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 |
Why wa?痛苦ing...In Reply To:读不懂了 Posted by:xiaomi at 2003-07-20 15:59:23 #include <iostream.h> int i,j,m,n,p; char str[3]; bool found,inc; bool **c; char *route; void judge() { int i,j,k,len=0; int flag; bool seq,**d,*del; d=new bool* [n]; del=new bool [n]; for (i=0;i<n;i++) { d[i]=new bool [n]; del[i]=0; for (j=0;j<n;j++) d[i][j]=c[i][j]; } seq=true; while (len<n) { flag=0; for (i=0;i<n;i++) { if (del[i]) continue; for (j=0;j<n;j++) if (d[j][i]==1) break; if (j==n) { flag++; k=i; } if (flag>1) break; } if (flag==0) { inc=true; break; } else { del[k]=1; if (flag>1) seq=false; route[len]=k+65; len++; for (j=0;j<n;j++) d[k][j]=0; } } if (seq) found=true; delete[] del; delete[] d; } int main() { cin>>n>>m; while (n!=0) { c=new bool* [n]; route=new char [n]; for (i=0;i<n;i++) { c[i]=new bool [n]; for (j=0;j<n;j++) c[i][j]=0; } found=inc=false; for (i=0;i<m;i++) { cin>>str; c[str[0]-65][str[2]-65]=1; if (!inc&&!found) { judge(); if (inc) cout<<"Inconsistency found after "<<i+1<<" relations."<<endl; else if (found) { cout<<"Sorted sequence determined after "<<i+1<<" relations: "; for (j=0;j<n;j++) cout<<route[j]; cout<<"."<<endl; } } } if (!inc&&!found) cout<<"Sorted sequence cannot be determined."<<endl; delete[] c; cin>>n>>m; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator