MasssA


私信TA

用户名:1294309339

访问量:34876

签 名:

城市学院的渣渣

等  级
排  名 104
经  验 7932
参赛次数 6
文章发表 73
年  龄 0
在职情况 学生
学  校 城市学院的渣渣
专  业

  自我简介:

城市学院的渣渣

解题思路:

注意事项:

#include <bits/stdc++.h> 

using namespace std; 

typedef long long LL; 

int n; 

string order; 

string Left,Right,oper; 

string Hex="10"; 

//任意进制转换为十进制  

LL hexToTen(string num)

{

      LL HEX=atoll(Hex.c_str());

   LL res=0,tmp=1;

    for (int i=num.size()-1;i>=0;i--){

     int base;

     if (num[i]>='A'&&num[i]<='Z'){

     base=num[i]-'A'+10;

         }

else{

  base=num[i]-'0'; 

res+=tmp*base; 

tmp*=HEX; 

return res; 

LL getResult()

         LL a=atoll(Left.c_str());

     LL b=atoll(Right.c_str());

LL c=0; 

if (oper=="ADD"){

     c=a+b;

     }

if (oper=="SUB"){ 

      c=a-b; 

if (oper=="MUL"){ 

      c=a*b;

if (oper=="DIV"){

      c=a/b; 

if (oper=="MOD"){ 

     c=a%b; 

}

return c; 

//将结果转化为当前进制 ,并输出  

void hexToNow(LL result)

       if (result==0){ 

      puts("0");

  return; 

   } 

   vector <char> v; 

   LL HEX=atoll(Hex.c_str()); 

   LL t; 

   while (result!=0){ 

     t=result%HEX; 

if (t>=10){ 

v.push_back((char)('A'+t-10));

}

else{ 

v.push_back((char)(t+'0'));

result/=HEX; 

  } 

  for (int i=v.size()-1;i>=0;i--){

   cout << v[i];

  }

  cout << endl; 

void solveOper(string order,string num)

{

       char tmp[105]; 

   if (order=="NUM"){

    if (oper==""){

sprintf(tmp,"%lld",hexToTen(num));

  Left=string(tmp); 

}

    else{

sprintf(tmp,"%lld",hexToTen(num)); 

Right=string(tmp); 

sprintf(tmp,"%lld",getResult()); 

Left=string(tmp); oper=Right=""; 

  }

  else if (order=="CHANGE"){

   Hex=num;

  }

  else if (order=="EQUAL"){ 

  hexToNow(atoll(Left.c_str()));

  } 

  else if (order=="CLEAR"){ 

     Left=oper=Right=""; 

  } 

  else{

   oper=order; 

  }

int main()

{

    cin >> n; 

getchar(); 

while (n--){ 

   getline(cin,order); 

   int index=order.find(' '); 

   if (index < 0){ 

      solveOper(order,"");

       }

       else{ 

      solveOper(order.substr(0,index),order.substr(index+1)); 

   } 

    } 

}





 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

我能问问题么。。。我写的在官网只能跑30分。。。
2020-02-22 18:46:53
  • «
  • 1
  • »