为什么我的代码在本地上可以跑,在洛谷就会全部WA呢
查看原帖
为什么我的代码在本地上可以跑,在洛谷就会全部WA呢
601645
wangweiye1205楼主2021/11/30 16:47
#include<iostream>
#include<deque>
#include<stack>
using namespace std;
stack<int> stk1;
stack<int> stk2;
stack<char> result;
int main()
{
    int c;
    while((c=getchar())!='\n'&&c!=' '&&c!='\t')
    {
        stk1.push(c-'0');
    }
    while((c=getchar())!='\n'&&c!=' '&&c!='\t'&&c!=EOF)
    {
        stk2.push(c-'0');
    }
    int past=0;
    char tem;
    while(!stk1.empty())
    {
        if(!stk2.empty())
        {
            tem=stk1.top()+stk2.top()+past;
            past=tem/10;
            result.push(tem%10);
            stk1.pop();
            stk2.pop();
        }
        else{
            if(!stk1.empty())
            {
                result.push(stk1.top()+past);
                past=0;
                stk1.pop();
            }
            while(!stk1.empty())
            {
                result.push(stk1.top());
                stk1.pop();
            }
        }
    }
    if(!stk2.empty())
    {
            result.push(stk2.top()+past);
            past=0;
            stk2.pop();
    }
    while(!stk2.empty())
    {
        result.push(stk2.top());
        stk2.pop();
    }
    if(past!=0)
    {
        printf("%d",past);
    }
    while(!result.empty())
    {
        printf("%d",result.top());
        result.pop();
    }

}
2021/11/30 16:47
加载中...