1 条题解

  • 0
    @ 2024-12-24 10:06:06

    C :

    
    #include<stdio.h>
    
    
    
    int main()
    {
    	int a,b,c,p=0;
    	char s[10];
    	while(scanf("%s",&s)!=EOF)
    	{	
    		if(sscanf(s,"%d+%d=%d",&a,&b,&c)==3&&(a+b==c)) p++;
    		if(sscanf(s,"%d-%d=%d",&a,&b,&c)==3&&(a-b==c)) p++;
    		
    		
    
    	}
    	printf("%d\n",p);
    	return 0;
    }
    
    
    
    
    

    C++ :

    #include<iostream>
    #include<cstring>
    using namespace std;
    
    int main(void)
    {
    	int a,b,c,t,sum=0;
    	char ch1,ch2;
    	int count=0;
    	char str[4];
    	int len=0;
    	while(cin>>a>>ch1>>b>>ch2>>str)	
    	{
    		if(str[0]=='?')
               continue;
           else if(str[0]!='?')
           { 
              len=strlen(str);
    		  c=0,t=1;
             for(int i=len-1;i>=0;i--)
    		 {
    			 c=c+(str[i]-'0')*t;
    			 t=t*10;
    		 }
    	   }
    		switch(ch1)
    		{
    			case '+':
    				{
    					sum=a+b;
    					if(sum==c)
    					{
    						count++;
    					}
    				}
    			case '-':
    				{
    					sum=a-b;
    					if(sum==c)
    					{
    						count++;
    					}
    				}
    			}
    	}
    	cout<<count<<endl;
    	return 0;
    }
    
    
    
    
    • 1

    信息

    ID
    1930
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者