为啥样例对了,判断点全WA不给过!!!

P1957 口算练习题

zyongbin @ 2021-12-21 12:25:26

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <malloc.h>
#include <limits.h>
char a[20]={0},b[20]={0},c[20]={0},d[100]={0};
int main()
{
   int n,j,l,q,x,y,z;
   char p;
   scanf("%d",&n);
   getchar();
   while(n--)
   {
       j=0,l=0,q=0;
       gets(a);
       for(int i=0;i<strlen(a);i++)
       {
           if(a[i]>='a'&&a[i]<='c')
           {
               if(a[i]=='a')p='a';
               else if(a[i]=='b')p='b';
               else p='c';
           }
           if(a[i]>='0'&&a[i]<='9'&&q==0)
           {
             b[j++]=a[i];
           }
           if(a[i-1]>='0'&&a[i-1]<='9'&&a[i]==' ')
           {
               q=1;
               sscanf(b,"%d",&x);
           }
           if(a[i]>='0'&&a[i]<='9'&&q==1)
           {
             c[l++]=a[i];
           }
           if(a[i]>='0'&&a[i]<='9'&&a[i+1]=='\0'&&q==1||a[i]>='0'&&a[i]<='9'&&a[i+1]==' '&&q==1)
           {
               sscanf(c,"%d",&y);
               break;
           }
       }
       switch(p)
       {
        case 'a':z=x+y,sprintf(d,"%d+%d=%d",x,y,z),printf("%s\n%d",d,strlen(d));break;
        case 'b':z=x-y,sprintf(d,"%d-%d=%d",x,y,z),printf("%s\n%d",d,strlen(d));break;
        case 'c':z=x*y,sprintf(d,"%d*%d=%d",x,y,z),printf("%s\n%d",d,strlen(d));break;
       }
       memset(d,'\0',sizeof(d));
       memset(b,'\0',sizeof(b));
       memset(c,'\0',sizeof(c));
        if(n!=0)
        printf("\n");
   }
   return 0;
}

by wwz1428572008 @ 2021-12-21 19:50:48

因为洛谷评测机采用的换行符是\r\n两个字符,需要getchar()两次。


by Starship_ @ 2022-01-02 23:06:45

@wwz1428572008 谢谢大佬,我也是这样,原来洛谷换行符是两个字符吗,终于解决了,谢谢!


by cxdm_0 @ 2022-06-18 14:41:34

@wwz1428572008 大佬神了,被这个问题困扰好久了。


|