我太菜了,A+B都过不去,还谈什么AKIOI
  • 板块P1001 A+B Problem
  • 楼主zxh_qwq
  • 当前回复18
  • 已保存回复18
  • 发布时间2023/3/11 12:58
  • 上次更新2023/10/23 21:56:37
查看原帖
我太菜了,A+B都过不去,还谈什么AKIOI
919709
zxh_qwq楼主2023/3/11 12:58
#include<bits/stdc++.h>
#define do_not_copy return 0;
using namespace std;
enum tnum{
    a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=0//枚举类型
};
short stoi(tnum aa){
    return short(aa);
}
tnum itos(short aa){
    return tnum(aa);
}//转换
struct s_int{
    queue<tnum> q;
    void int_in(){
        char cc;
        while(q.size())q.pop();//清空
        while(cc!=' '&&cc!='\n')
        {
            cc=getchar();
            if(cc==' ')break;
            tnum t;
            switch(cc){//Switch
                case '0':t=j;break;
                case '1':t=a;break;
                case '2':t=b;break;
                case '3':t=c;break;
                case '4':t=d;break;
                case '5':t=e;break;
                case '6':t=f;break;
                case '7':t=g;break;
                case '8':t=h;break;
                case '9':t=i;break;
                default:return;
            }
            q.push(t);//插入
        }
    }
    void int_out(){
        queue<tnum> tempq=q;
        while(tempq.size()){
            if(tempq.size())
            cout<<tempq.front();//循环输出
            tempq.pop();
        }
    }
    s_int operator + (s_int b)//重定义
    {
        queue<tnum> aq=q,bq=b.q;
        stack<tnum> ts1,ts2,ts3;
        while(aq.size()){
            ts1.push(aq.front());
            aq.pop();
        }
        while(bq.size()){
            ts2.push(bq.front());
            bq.pop();
        }//翻转
        bool c=0;
        while(ts1.size()||ts2.size()){
            short a=ts1.top(),b=ts2.top();
            ts1.pop(),ts2.pop();
            ts3.push(itos((a+b+c)%10));
            c=(a+b)/10;
        }//高精
        while(ts1.size()){
            ts3.push(itos(stoi(ts1.top())+1));
            ts1.pop();
        }
        while(ts2.size()){
            ts3.push(itos(stoi(ts2.top())+1));
            ts2.pop();
        }//处理剩下部分
        s_int d;
        while(ts3.size()){
            d.q.push(ts3.top());
            ts3.pop();
        }//转换
        return d;
    }
};
int main(){
    s_int a,b;
    a.int_in();
    b.int_in();
    s_int c=a+b;
    c.int_out();
    do_not_copy//6
}
2023/3/11 12:58
加载中...