zoj 3432 与运算运用

  1. /****************************************************
  2. 该题充分运用与运算的特点,成对消除,单的最后留下
  3. ****************************************************/
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <algorithm>
  7. using namespace std;
  8. int main()
  9. {
  10. char str1[10], str2[10];
  11. int n;
  12. while(~scanf("%d", &n) )
  13. {
  14. getchar();
  15. gets(str1);
  16. for(int i=0; i<2*n-2; i++)
  17. {
  18. gets(str2);
  19. for(int j=0; j<7; j++)
  20. str1[j] = str1[j] ^ str2[j]; //两个字符串各自与运算,可以判定最后剩下的不成对的一个
  21. }
  22. printf("%s\n", str1);
  23. }
  24. }
  25. /*
  26. Description
  27. Alice bought a lot of pairs of socks yesterday. But when she went home, she found that she has lost one of them. Each sock has a name which contains exactly 7 charaters.
  28. Alice wants to know which sock she has lost. Maybe you can help her.
  29. Input
  30. There are multiple cases. The first line containing an integer n (1 <= n <= 1000000) indicates that Alice bought n pairs of socks. For the following 2*n-1 lines, each line is a string with 7 charaters indicating the name of the socks that Alice took back.
  31. Output
  32. The name of the lost sock.
  33. Sample Input
  34. 2
  35. aabcdef
  36. bzyxwvu
  37. bzyxwvu
  38. 4
  39. aqwerty
  40. eas fgh
  41. aqwerty
  42. easdfgh
  43. easdfgh
  44. aqwerty
  45. aqwerty
  46. 2
  47. 0x0abcd
  48. 0ABCDEF
  49. 0x0abcd
  50. Sample Output
  51. aabcdef
  52. eas fgh
  53. 0ABCDEF
  54. */





附件列表

     

    posted @ 2015-01-29 11:37  sober_reflection  阅读(112)  评论(0编辑  收藏  举报