fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int T[1000007];
  6. int A[1000007];
  7. int P[1000007];
  8.  
  9.  
  10. int main()
  11. {
  12. int t, n;
  13.  
  14. scanf("%d", &t);
  15. for(int zi=0; zi<t; zi++)
  16. {
  17. scanf("%d", &n);
  18. for(int i = 0; i < n; i++) scanf("%d", &T[i]);
  19.  
  20. bool ok = true;
  21. for(int i = 0; i < n/2; i++)
  22. {
  23. int suma = T[i] + T[n-1-i];
  24. if (suma & 1) ok = false;
  25. P[i]=suma/2; P[n-1-i]=P[i];
  26. A[i]=T[i]-P[i];
  27. A[n-1-i] = T[n-1-i] - P[n-1-i];
  28. }
  29. if (ok)
  30. {
  31. for(int i = 0; i < n; i++) printf("%d ", P[i]);
  32. printf("\n");
  33. for(int i = 0; i < n; i++) printf("%d ", A[i]);
  34. printf("\n");
  35. }else printf("NIE\n");
  36.  
  37. }
  38. return 0;
  39. }
  40.  
stdin
3
2
1 1
4
1 2 4 5
4
1 2 3 4
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
1 1 
0 0 
3 3 3 3 
-2 -1 1 2 
NIE