题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1711
input | output |
---|---|
11 cipher grille kamkohob names codenames codes newtests rejudge timus size volume summit watchmen braineater twosides solution random yesorno keywords subversion commands bosses shooting shaitan game strategy playgame mnemonic palindromes bestname eligibility rectangle rules 2 1 7 10 9 6 11 3 8 4 5 |
codenames grille keywords mnemonic playgame random rectangle rejudge shaitan volume watchmen |
3 problems in the first sample are ordered not randomly 1 2 3 |
IMPOSSIBLE |
代码如下:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int main() { int n; string s[27][27]; while(~scanf("%d",&n)) { for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { cin >> s[i][j]; } sort(s[i],s[i]+3); // for(int j = 0; j < 3; j++) // { // cout<<s[i][j]<<endl; // } } int num; string ans[27]; string tt=""; int flag = 0; for(int i = 0; i < n; i++) { scanf("%d",&num); num--; if(i == 0)//最小的 { tt = s[num][0]; ans[0] = tt; continue; } //cout<<"tt:"<<tt<<endl; int mark = 0; for(int j = 0; j < 3; j++) { mark = 0; if(s[num][j] > tt) { mark = 1; tt = s[num][j]; //cout<<"tt:"<<tt<<endl; ans[i] = s[num][j]; break; } } if(mark == 0) { flag = 1; } } if(flag == 1) { printf("IMPOSSIBLE\n"); continue; } for(int i = 0; i < n; i++) { cout<<ans[i]<<endl; } } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/44201303