wojiaocbj

Untitled

May 21st, 2022
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #pragma warning(disable:4996)
  7. typedef long long s64, LL;
  8. typedef unsigned long long u64, ULL;
  9. typedef const void *cvp;
  10. #define MAX(a,b) (((a)>(b))?(a):(b))
  11. int arr[6000010] = { 0 };
  12. int main(){
  13. #ifdef _DEBUG
  14.     FILE *fp = freopen("../../../input.txt", "r", stdin);
  15.     //FILE *fp2 = freopen("../../../output.txt", "w", stdout);
  16. #endif // _DEBUG
  17.     int n, i, ans = 0, ans1;
  18.     scanf("%d", &n);
  19.     for(i = 0; i < n; i++){
  20.         scanf("%d", arr + i);
  21.         ans ^= arr[i];
  22.     }
  23.     if(n & 1){//奇数直接出答案
  24.         printf("%d\n", ans);
  25.     }
  26.     else if(!ans){
  27.         puts("False Alarm.");
  28.     }
  29.     else{
  30.         ans1 = ans;
  31.         int pos = 1, k;
  32.         for(k = 0; k < 32; k++){
  33.             if(ans1 & (1 << k)){
  34.                 pos = (1 << k); break;
  35.             }
  36.         }
  37.         for(i = 0; i < n; i++){
  38.             if(arr[i] & pos){
  39.                 ans ^= arr[i];
  40.             }
  41.             else{
  42.                 ans1 ^= arr[i];
  43.             }
  44.         }
  45.         if(ans < ans1){
  46.             printf("%d %d\n", ans, ans1);
  47.         }
  48.         else{
  49.             printf("%d %d\n", ans1, ans);
  50.         }
  51.     }
  52. #ifdef _DEBUG
  53.     fp = freopen("CON", "r", stdin);
  54.     //fp2 = freopen("CON", "w", stdout);
  55.     system("pause");
  56. #endif // _DEBUG
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment