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 |
runtime error 怎么解决#include<stdio.h> int s[26][26]; int m, n; char ch[26]; int top_sort(){ int i,j,k,c,g=0,t[26]; char o; for(i=0;i<n;i++)t[i]=0; for(k=0;k<n;k++){ c=0; for(i=0;i<n;i++)if(t[i]==0){ for(j=0;j<n;j++)if(t[j]==0&&s[j][i]==1)break; if(j==n){o=char('A'+i);c++;} } t[o-'A']=1; if(c==0)return 1; if(c==1){ch[g++]=o;if(g==n)return 2;} if(c>1)break; } for(i=0;i<n;i++)t[i]=0; for(k=0;k<n;k++){ c=0; for(i=0;i<n;i++)if(t[i]==0){ for(j=0;j<n;j++)if(t[j]==0&&s[j][i]==1)break; if(j==n){o=char('A'+i);c++;} } t[o-'A']=1; if(c==0)return 1; } return 0; } void Sort(){ int i,j,k; char str[1000][3]; for(i=0;i<n;i++) for(j=0;j<n;j++)s[i][j]=0; for(k=0;k<m;k++){ scanf("%s",str[k]); s[str[k][0]-'A'][str[k][2]-'A']=1; j=top_sort(); if(j!=0){i=k+1;goto loop;} } loop:for(k++;k<m;k++)scanf("%s"); if(j==0)printf("Sorted sequence cannot be determined.\n"); if(j==1)printf("Inconsistency found after %d relations.\n",i); if(j==2) { printf("Sorted sequence determined after %d relations: ",i); for(i=0;i<n;i++)printf("%c",ch[i]); printf(".\n"); } } int main(){ scanf("%d",&n); scanf("%d",&m); while(m*n!=0){ Sort(); scanf("%d",&n); scanf("%d",&m); } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator