Advertisement
Kaidul

uva - 10931

Jan 7th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cctype>
  4. #include <cmath>
  5. #include <complex>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include <deque>
  11. #include <fstream>
  12. #include <iostream>
  13. #include <list>
  14. #include <climits>
  15. #include <map>
  16. #include <memory>
  17. #include <queue>
  18. #include <set>
  19. #include <sstream>
  20. #include <stack>
  21. #include <string>
  22. #include <utility>
  23. #include <vector>
  24. #include <iomanip>
  25.  
  26. using namespace std;
  27.  
  28. #define REP(i,n) for(__typeof(n) i=0; i<(n); i++)
  29. #define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
  30. #define RFOR(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
  31. #define RESET(t,value) memset((t), value, sizeof(t))
  32.  
  33. #define READ(f) freopen(f, "r", stdin)
  34. #define WRITE(f) freopen(f, "w", stdout)
  35.  
  36. #define PI acos(-1.0)
  37. #define INF (1<<30)
  38. #define eps 1e-8
  39. #define pb push_back
  40. #define ppb pop_back
  41. #define pii pair<int, int>
  42. #define G struct Graph
  43.  
  44. typedef long long int64;
  45. typedef unsigned long long ui64;
  46. typedef long double d64;
  47.  
  48. template< class T > T gcd(T a, T b) {
  49.     return (b != 0 ? gcd<T>(b, a%b) : a);
  50. }
  51. template< class T > T lcm(T a, T b) {
  52.     return (a / gcd<T>(a, b) * b);
  53. }
  54. template< class T > void setmax(T &a, T b) {
  55.     if(a < b) a = b;
  56. }
  57. template< class T > void setmin(T &a, T b) {
  58.     if(b < a) a = b;
  59. }
  60.  
  61. vector < int > pset;
  62. void initSet(int _size) {
  63.     pset.resize(_size);
  64.     FOR(i,0,_size-1) pset[i]=i;
  65. }
  66. int findSet(int i) {
  67.     return (pset[i]== i)?i: (pset[i] = findSet(pset[i]));
  68. }
  69. void unionSet(int i,int j) {
  70.     pset[findSet(i)]=findSet(j);
  71. }
  72. bool isSameSet(int i,int j) {
  73.     return findSet(i)==findSet(j);
  74. }
  75.  
  76. #define Max 100
  77. /* @code starts */
  78. bool Check(int n, int pos) {
  79.     return (bool)(n & (1 << pos));
  80. }
  81.  
  82. int Set(int n, int pos) {
  83.     return n = n | (1 << pos) ;
  84. }
  85.  
  86. int main() {
  87.     //READ("input.txt");
  88.     int n;
  89.     while (cin >> n && n) {
  90.  
  91.         int status;
  92.         int parity = 0;
  93.         REP(i, 32) {
  94.             status = Set(n, i);
  95.             if (Check(n, i )) {
  96.                 parity++;
  97.             }
  98.         }
  99.         cout << "The parity of ";
  100.         bool flag = false;
  101.         RFOR( i, 30, 0 ) {
  102.             bool result = Check(status, i);
  103.             if (flag) {
  104.                 cout << result;
  105.                 continue;
  106.             }
  107.  
  108.             if(result) {
  109.                 cout << result;
  110.                 flag = true;
  111.             }
  112.         }
  113.         cout << " is " << parity << " (mod 2).\n";
  114.     }
  115.     return EXIT_SUCCESS;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement