wrench786

Spokes Wheel UVALive - 6809

Apr 30th, 2023
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. typedef long long ll;
  3. typedef unsigned long long ull;
  4. #define nn "\n"
  5. #define mod 1000000007
  6. using namespace std;
  7.  
  8. int cases=0;
  9.  
  10. string htb(char x){
  11.     int n;
  12.     if(x>='0' && x<='9') n = x-'0';
  13.     else if(x=='A') n=10;
  14.     else if(x=='B') n=11;
  15.     else if(x=='C') n=12;
  16.     else if(x=='D') n=13;
  17.     else if(x=='E') n=14;
  18.     else if(x=='F') n=15;
  19.  
  20.     string ans="";
  21.     while(n){
  22.         ans+=(n%2==0)?'0':'1';
  23.         n/=2;
  24.     }
  25.     reverse(ans.begin(),ans.end());
  26.     while((int)ans.size()<4) ans='0'+ans;
  27.     return ans;
  28. }
  29.  
  30. // check int overflow
  31. void solve(){
  32.     string a,b;
  33.     cin>>a>>b;
  34.  
  35.     while((int)a.size()<8) a='0'+a;
  36.     while((int)b.size()<8) b='0'+b;
  37.  
  38.     string aa="",bb="";
  39.  
  40.     for(int i=0;i<8;i++){
  41.         string dum = htb(a[i]);
  42.         aa=aa+dum;
  43.     }
  44.     for(int i=0;i<8;i++){
  45.         string dum = htb(b[i]);
  46.         bb=bb+dum;
  47.     }
  48.  
  49.     // cout<<aa<<nn;
  50.     // cout<<bb<<nn;
  51.  
  52.  
  53.     bool flag=0;
  54.     cout<<"Case #"<<++cases<<": ";
  55.    
  56.     for(int i=0;i<32;i++){
  57.         string x = aa.substr(0,i);
  58.         string y = aa.substr(i);
  59.  
  60.         if(y+x==bb){
  61.             flag=1;
  62.             if(i<32-i){
  63.                 cout<<i<<" Left"<<nn;
  64.             }
  65.             else if(i==32-i){
  66.                 cout<<i<<" Any"<<nn;
  67.             }
  68.             else{
  69.                 cout<<32-i<<" Right"<<nn;
  70.             }
  71.             break;
  72.         }
  73.     }
  74.     if(!flag) cout<<"Not possible";
  75. }
  76.  
  77. int main()
  78. {
  79.     // freopen("reduce.in", "r", stdin);
  80.     // freopen("reduce.out", "w", stdout);
  81.     int tc=1;
  82.     cin>>tc;
  83.    
  84.     ///scanf("%d",&tc);  
  85.     while(tc--){
  86.         solve();
  87.     }
  88.     return 0;
  89. }
Tags: Blue Problem
Advertisement
Add Comment
Please, Sign In to add comment