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 |
Re:偶的解法:)In Reply To:偶的解法:) Posted by:devilphoenix at 2006-05-23 18:00:20 NB的解法,已经按照大人的要求实现出来了,一遍过.高明啊 /* 先把light,heavy设为全集,每次得到light'和heavy'进行以下操作 light=light交light',light=light-heavy heavy=heavy交heavy,heavy=heavy-light 最后在light和heavy里面找只剩下一个元素的那个集合,然后把这个元素打印出来就ok even的就是。。 light=light-even right=right-even */ #include <iostream> #include <string.h> using namespace std; int main() { int i, j, k, l; int n; char light[91], heavy[91], tleft[10], tright[10], temp[10]; cin>>n; for (i = 0; i < n; i++) { for (j = 65; j < 77; j++) { light[j] = 1; heavy[j] = 1; } for (j = 0; j < 3; j++) { cin>>tleft>>tright>>temp; if (strcmp(temp, "even") == 0) { for (k = 0; k < strlen(tleft); k++) { light[tleft[k]] = 0; light[tright[k]] = 0; } for (k = 0; k < strlen(tright); k++) { heavy[tleft[k]] = 0; heavy[tright[k]] = 0; } } if (strcmp(temp, "up") == 0) { for (k = 0; k < strlen(tleft); k++) heavy[tleft[k]]++; for (k = 65; k < 77; k++) if (heavy[k] == 2) heavy[k] = 1; else heavy[k] = 0; for (k = 0; k < strlen(tright); k++) heavy[tright[k]] = 0; for (k = 0; k < strlen(tright); k++) light[tright[k]]++; for (k = 65; k < 77; k++) if (light[k] == 2) light[k] = 1; else light[k] = 0; for (k = 0; k < strlen(tleft); k++) light[tleft[k]] = 0; } if (strcmp(temp, "down") == 0) { for (k = 0; k < strlen(tright); k++) heavy[tright[k]]++; for (k = 65; k < 77; k++) if (heavy[k] == 2) heavy[k] = 1; else heavy[k] = 0; for (k = 0; k < strlen(tleft); k++) heavy[tleft[k]] = 0; for (k = 0; k < strlen(tleft); k++) light[tleft[k]]++; for (k = 65; k < 77; k++) if (light[k] == 2) light[k] = 1; else light[k] = 0; for (k = 0; k < strlen(tright); k++) light[tright[k]] = 0; } } for (k = 65; k < 77; k++) if (light[k] == 1) cout<<k<<" is the counterfeit coin and it is light."<<endl; for (k = 65; k < 77; k++) if (heavy[k] == 1) cout<<k<<" is the counterfeit coin and it is heavy."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator