Advertisement
Saleh127

UVA 466

Nov 11th, 2020
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main ()
  4. {
  5. int n, a, b, result;
  6. char c;
  7.  
  8. cin >> n;
  9.  
  10. while (n--)
  11. {
  12. cin >> hex >> a >> c >> hex >> b;
  13.  
  14. if (c == '+') result = a + b;
  15.  
  16. else result = a - b;
  17.  
  18. cout << bitset<13>(a) << " " << c << " " << bitset<13>(b) << " = " << result << endl;
  19. }
  20.  
  21. return 0;
  22. }
  23.  
  24.  
  25.  
  26.  
  27. ///in c AC
  28. /*
  29. #include <stdio.h>
  30. int main()
  31. {
  32. int t;
  33. scanf("%d",&t);
  34. while(t--)
  35. {
  36. int a[100],b[100];
  37. char c;
  38. int d,e,f,i,j,k,l;
  39.  
  40. scanf("%X %c %X",&d,&c,&e);
  41. if(c=='+')
  42. {
  43. f=d+e;
  44. }
  45. else f=d-e;
  46.  
  47. for(i=0; i<13; i++)
  48. {
  49. a[i]=(d%2);
  50. d/=2;
  51. }
  52. for(i=0; i<13; i++)
  53. {
  54. b[i]=(e%2);
  55. e/=2;
  56. }
  57. for(i=12; i>=0; i--)
  58. {
  59. printf("%d",a[i]);
  60. }
  61. printf(" %c ",c);
  62. for(i=12; i>=0; i--)
  63. {
  64. printf("%d",b[i]);
  65. }
  66. printf(" = %d\n",f);
  67.  
  68. }
  69. return 0;
  70. }
  71. */
  72.  
Advertisement
RAW Paste Data Copied
Advertisement