在codeblocks上运行没问题,提交后显示编译失败,为什么?
查看原帖
在codeblocks上运行没问题,提交后显示编译失败,为什么?
1490481
Steven0904楼主2024/12/20 19:30
#include<iostream>
using namespace std;
char a=0;
int p=0,q=0;
int n;
int l(int x)
{
    int len;
    if(x==0) return 1;
    if(x>0)
    {
        len=0;
        int test=1;
        while(x-test>=0)
        {
            len++;
            test*=10;
        }
        return len;
    }
    if(x<0)
    {
        len=1;
        int test=1;
        while(x+test<=0)
        {
            len++;
            test*=10;
        }
    }
    return len;
}

int main()
{
    cin>>n;
    char str[90][90]={0};
    char c;
    while((c=getchar())!='\n'){}
    for(int i=1;i<=n;i++)
    {
        gets(str[i]);
    }
    char rem;
    for(int i=1;i<=n;i++)
    {
        if(str[i][0]>=96) sscanf(str[i],"%c %d %d",&a,&p,&q);
        else sscanf(str[i],"%d %d",&p,&q);
        int res,len;
        if(a=='a')
        {
            res=p+q;
            cout<<p<<"+"<<q<<"="<<res<<endl;
            len=1+l(p)+l(q)+1+l(res);
            cout<<len<<endl;
        }
        if(a=='b')
        {
            res=p-q;
            cout<<p<<"-"<<q<<"="<<res<<endl;
            len=1+l(p)+l(q)+1+l(res);
            cout<<len<<endl;
        }
        if(a=='c')
        {
            res=p*q;
            cout<<p<<"*"<<q<<"="<<res<<endl;
            len=1+l(p)+l(q)+1+l(res);
            cout<<len<<endl;
        }
    }
    return 0;
}

求助,感谢!

2024/12/20 19:30
加载中...