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 |
为什么我的代码一直是WA请问哪位大牛看看是那里错了 #include <iostream> #include <stack> using namespace std; struct Point { int Indeg; int Outdeg; }; Point Points[26]; bool isvisted[26]; bool way[26][26]; int main() { char temp[2000]; int n; int m; cin>>n; while(n--) { int a=sizeof(way); for(int i=0; i<26; i++) { isvisted[i]=true; Points[i].Indeg=0; Points[i].Outdeg=0; for(int j=0; j<26; j++) way[i][j]=false; } cin>>m; while(m--) { cin>>temp; Points[temp[0]-'a'].Outdeg++; Points[temp[strlen(temp)-1]-'a'].Indeg++; way[temp[0]-'a'][temp[strlen(temp)-1]-'a']=true; isvisted[temp[0]-'a']=false; isvisted[temp[strlen(temp)-1]]=false; } bool isok=true; int begin=0; int end=0; for(int i=0 ;i<26; i++) { if(Points[i].Indeg==Points[i].Outdeg+1) end++; else if(Points[i].Indeg==Points[i].Outdeg-1) begin++; else if(Points[i].Indeg==Points[i].Outdeg) continue; else { isok=false; break; } } if(begin==0 && end==0 || (begin==1 &&end==1)) isok=isok && true; else isok=false; if(!isok) { cout<<"The door cannot be opened."<<endl; continue; } stack<int> mystack; if(begin==0) { for(int i=0; i<26; i++) { if(isvisted[i]==false) { isvisted[i]=true; mystack.push(i); break; } } } else { for(int i=0; i<26; i++) { if(isvisted[i]==false && Points[i].Indeg==Points[i].Outdeg-1) { isvisted[i]=true; mystack.push(i); break; } } } while(!mystack.empty()) { int mid=mystack.top(); mystack.pop(); for(int i=0; i<26; i++) { if(way[mid][i]==true && isvisted[i]==false) { isvisted[i]=true; mystack.push(i); } } } for(int i=0; i<26; i++) { if(isvisted[i]==false) { isok=false; break; } } if(isok) cout<<"Ordering is possible."<<endl; else cout<<"The door cannot be opened."<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator