这里样例都是对的但是提交就一个都过不去,怎么办,求救!!!

P1957 口算练习题

ZBH84107855 @ 2022-11-14 12:27:32

#include <stdio.h>
#include <string.h>
void f(char *s,int len,char *p)
{
    int k1=0,k2=0;
    int c=0;
    int sum1=0,sum2=0;
    switch(s[0])
    {
        case'a':*p='a';break;
        case'b':*p='b';break;
        case'c':*p='c';break;
        default:break;
    }
    int i=0;
    if(s[0]=='a'||s[0]=='b'||s[0]=='c')
     i=i+2;
    for(;i<len;i++)
    {   

        while(s[i]>='0'&&s[i]<='9'&&i<len)
        {           
            if(s[i]>='0'&&s[i]<='9'&&c==0)
            {
                sum1=sum1*10+(s[i]-'0');
                k1++;
            }           
            if(s[i]>='0'&&s[i]<='9'&&c==1)
            {
                sum2=sum2*10+(s[i]-'0');
                k2++;
            }            
            i++;
        }
        if(s[i]==' ') c=1;
    }
    int r=0;
    if(*p=='a') r=sum1+sum2;
    if(*p=='b') r=sum1-sum2;
    if(*p=='c') r=sum1*sum2;
    int k,count;
    k=r;count=0;
    if(k<0) k=k*(-1);
    while(k>0)
    {
        k/=10;
        count++;
    }
    if(r<0) count++;
    if(*p=='a') printf("%d+%d=%d\n%d",sum1,sum2,r,count+k1+k2+2);
    if(*p=='b') printf("%d-%d=%d\n%d",sum1,sum2,r,count+k1+k2+2);
    if(*p=='c') printf("%d*%d=%d\n%d",sum1,sum2,r,count+k1+k2+2);
}

int main()
{
    int n,i;
    scanf("%d",&n);
    getchar();
    char p;
    char str[n][1000],s[1000];
    for(i=0;i<n;i++)
        gets(str[i]);
    int len;
    for(i=0;i<n;i++)
    {
        strcpy(s,str[i]);
        len=strlen(s);
        f(s,len,&p);
        if(i!=n-1) printf("\n"); 
    }
}

by greenwood2022 @ 2022-11-17 14:20:24

我也是有找到解决的方法吗我真的不能理解


|