RE了,求大佬解答!!

B2052 简单计算器

python18 @ 2023-12-06 21:10:04

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int j,k;
    char g;
    cin>>j>>k;
    cin>>g;
    if(k==0&&g=='/')
    {
        printf("Divided by zero!\n");
    }
    if(g!='+'&&g!='-'&&g!='*'&&g!='/')
    {
        cout<<"Invalid operator!"<<endl;    
    }
    if(g=='+')
    {
        printf("%d\n",j+k);
    }
    else if(g=='-')
    {
        printf("%d\n",j-k);
    }
    else if(g=='*')
    {
        printf("%d\n",j*k);
    }
    else if(g=='/')
    {
        printf("%d",j/k);
    }

    return 0;
} 

RE了,求大佬解答,球球了


by Carlos20130721 @ 2024-07-28 16:43:34

include<bits/stdc++.h>

using namespace std; int main() { int a,b,ans; char c; cin>>a>>b>>c; if(c=='+') { ans=a+b; } else if(c=='-') { ans=a-b; } else if(c=='') { ans=ab; } else if(c=='/') { ans=a/b; if(a/b==0) { cout<<"Divided by zero!"<<endl; } } else { cout<<"Invalid operator!"<<endl; } cout<<ans<<endl; return 0; }


by Carlos20130721 @ 2024-07-28 16:45:36

第一个代码应该是:

include<bits/stdc++.h>

using namespace std;

int main()

{ int a,b,ans; char c; cin>>a>>b>>c; if(c=='+') { ans=a+b; } else if(c=='-') { ans=a-b; } else if(c=='') { ans=ab; } else if(c=='/') { ans=a/b; if(a/b==0) { cout<<"Divided by zero!"<<endl; } } else { cout<<"Invalid operator!"<<endl; } cout<<ans<<endl; return 0; }


by joe_001 @ 2024-08-08 16:05:50

@python18

人狠话不多

上代码!

顺便求个关注

▄█▀█●

求求了!

#include<bits/stdc++.h>
using namespace std;
long long x,y,k;
char z;
int main()
{   
    cin>>x>>y>>z;
    if(y==0 && z=='/')
    {
        cout<<"Divided by zero!"<<endl;
        return 0;
    }
    if(z!='+' && z!='-' && z!='*' && z!='/')
    {
        cout<<"Invalid operator!"<<endl;
        return 0;
    }
    if(z=='+')
        cout<<x+y;
    if(z=='-')
        cout<<x-y;
    if(z=='*')
        cout<<x*y;
    if(z=='/')
        cout<<x/y;
    return 0;
}

by _114514_114514_ @ 2024-08-30 10:51:23

同求


by _114514_114514_ @ 2024-08-30 10:52:14

@honglixian1118 借用一下你的代码,已关


上一页 |