Advertisement
erfanul007

UVa 446

Jul 3rd, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  26. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  27. #define cspf(i) printf("Case %d: ", i)
  28. #define pb push_back
  29. #define mp make_pair
  30. #define ff first
  31. #define ss second
  32. #define all(v) v.begin(),v.end()
  33. #define rall(v) v.rbegin(),v.rend()
  34. #define read() freopen("input.txt", "r", stdin)
  35. #define write() freopen("output.txt", "w", stdout)
  36. /// Constants
  37. #define eps 1e-9
  38. #define PI acos(-1.0) // 3.1415926535897932
  39. #define MAX 1000009*/
  40.  
  41. void fastIO()
  42. {
  43. ios_base::sync_with_stdio(false);
  44. cin.tie(NULL);
  45. }
  46.  
  47.  
  48. int main()
  49. {
  50. //read();
  51. //write();
  52. map<char,string>mp = {{'0',"0000"},{'1',"0001"},{'2',"0010"},{'3',"0011"},{'4',"0100"},{'5',"0101"},{'6',"0110"},{'7',"0111"},{'8',"1000"},{'9',"1001"},{'A',"1010"},{'B',"1011"},{'C',"1100"},{'D',"1101"},{'E',"1110"},{'F',"1111"}};
  53. //for(auto x : mp) cout<<x.second<<' ';
  54. int t;
  55. sci(t);
  56. while(t--){
  57. string b1="0",b2="0",s;
  58. char c;
  59. int t1=0,t2=0;
  60. cin>>s;
  61. loop(i,1,3-s.size()){
  62. b1+="0000";
  63. }
  64. loop(i,0,s.size()-1){
  65. b1+=mp[s[i]];
  66. }
  67. cout<<b1<<' ';
  68. for(int i=b1.size()-1,j=1;i>=0;i--,j*=2){
  69. t1+=((b1[i]-'0')*j);
  70. }
  71. cin>>c;
  72. cout<<c<<' ';
  73. cin>>s;
  74. loop(i,1,3-s.size()){
  75. b2+="0000";
  76. }
  77. loop(i,0,s.size()-1){
  78. b2+=mp[s[i]];
  79. }
  80. cout<<b2<<" = ";
  81. for(int i=b2.size()-1,j=1;i>=0;i--,j*=2){
  82. t2+=((b2[i]-'0')*j);
  83. }
  84. if(c=='+') pfi(t1+t2);
  85. else pfi(abs(t1-t2));
  86. line;
  87. }
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement