1 solutions

  • 0
    @ 2025-11-5 15:07:08

    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

    Information

    ID
    16416
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By