当前位置:首页 > Windows程序 > 正文

POJ 2585.Window Pains

2021-03-21 Windows程序

#include<iostream> #include<cstdio> #include<cstring> using namespace std; int L[10][10]; int indegree[10]; int TopSort(); int main() { int i,j,t; string cover[5][5]; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cover[i][j]+=j+1+i*3+‘0‘; cover[i][j+1]+=j+1+i*3+‘0‘; cover[i+1][j]+=j+1+i*3+‘0‘; cover[i+1][j+1]+=j+1+i*3+‘0‘; } } /** for(i=0; i<4; i++) { for(j=0; j<4; j++) { string::iterator y; for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y) { cout<<*y; } cout<<" "; } cout<<endl; } */ string s; while(cin>>s) { getchar(); if(s=="ENDOFINPUT") break; memset(indegree,0,sizeof(indegree)); memset(L,0,sizeof(L)); for(i=0; i<4; i++) { for(j=0; j<4; j++) { char x; scanf("%c",&x); string::iterator y; //指向STRING的迭代器,其实和指针的概念是一样。 for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y) { if((*y)!=x&&L[x-‘0‘][(*y)-‘0‘]==0) { L[x-‘0‘][(*y)-‘0‘]=1; indegree[(*y)-‘0‘]++; } } getchar(); } } cin>>s; getchar(); /** for(i=1; i<10; i++) { cout<<i<<":"; for(j=0; j<10; j++) { if(L[i][j]==1) cout<<j<<" "; } cout<<endl; } cout<<"indegree:"; for(i=1; i<10; i++) cout<<indegree[i]<<" "; cout<<endl; */ int flag=TopSort(); if(flag) cout<<"THESE WINDOWS ARE CLEAN"<<endl; else cout<<"THESE WINDOWS ARE BROKEN"<<endl; } return 0; } int TopSort() { int i,j; int n=9; int sign=0; while(n--) { sign=0; for(i=1; i<10; i++) { if(indegree[i]==0) sign=i; } if(sign>0) { for(j=0; j<10; j++) { if(L[sign][j]) indegree[j]--; } indegree[sign]=-1; } else if(sign==0) return 0; } return 1; }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/64887.html