結果

問題 No.2385 Parse Integer with Radix
ユーザー twooimptwooimp
提出日時 2023-07-21 22:11:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 3,264 ms
コンパイル使用メモリ 181,596 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 22:11:48
合計ジャッジ時間 2,175 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

ll p(ll a,ll n){
  ll res=1;
  while(n--){
    res*=a;
  }
  return res;
}

int main(){
  set<char> alp;
  alp.insert('a');
  alp.insert('b');
  alp.insert('c');
  alp.insert('d');
  alp.insert('e');
  alp.insert('f');
  map<char,ll> tra;
  tra['a']=10;
  tra['b']=11;
  tra['c']=12;
  tra['d']=13;
  tra['e']=14;
  tra['f']=15;
  ll q;
  cin>>q;
  while(q--){
    string s;
    cin>>s;
    ll n=s.size();
    ll ans=0;
    if(s[1]=='b'){
      reverse(s.begin(),s.end());
      s.pop_back();
      s.pop_back();
      n-=2;
      for(ll i=0;i<n;i++){
        ans+=(s[i]-'0')*p(2,i);
      }
      cout<<ans<<endl;
    }else if(s[1]=='o'){
      reverse(s.begin(),s.end());
      s.pop_back();
      s.pop_back();
      n-=2;
      for(ll i=0;i<n;i++){
        ans+=(s[i]-'0')*p(8,i);
      }
      cout<<ans<<endl;
    }else if(s[1]=='x'){
      reverse(s.begin(),s.end());
      s.pop_back();
      s.pop_back();
      n-=2;
      for(ll i=0;i<n;i++){
        if(alp.find(s[i])!=alp.end()){
          ans+=tra[s[i]]*p(16,i);
        }else{
          ans+=(s[i]-'0')*p(16,i);
        }
      }
      cout<<ans<<endl;
    }else if(s.size()<=2){
      cout<<s<<endl;
    }else{
      cout<<s<<endl;
    }
  }
}
0