Uva--340 (检索)
2014-06-02 16:46:25
题意&思路:简单的单次遍历检索。(以后要求输出空格的时候,直接从样例中取。。。这次傻X地PE两次)
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1000; int main(){ int n,Case = 0; int s[maxn + 5],g[maxn + 5],used[maxn + 5],ns,nw; while(scanf("%d",&n) == 1 && n){ for(int i = 0; i < n; ++i) scanf("%d",&s[i]); printf("Game %d:\n",++Case); while(scanf("%d",&g[0]) == 1){ for(int i = 1; i < n; ++i) scanf("%d",&g[i]); if(g[0] == 0) break; memset(used,0,sizeof(used)); ns = 0; nw = 0; for(int i = 0; i < n; ++i){ if(s[i] == g[i]){ used[i] = 1; ++ns; } else{ for(int j = 0 ; j < n; ++j){ if(!used[j] && s[i] == g[j] && s[j] != g[j]){ used[j] = 1; ++nw; break; } } } } printf(" (%d,%d)\n",ns,nw); } } return 0; }