Futaba_Shinaraku @ 2022-05-15 13:55:27
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,ans;char c;
cin>>a>>b>>c;
if(c==43)ans=a+b;
else if(c==45)ans=a-b;
else if(c==34)ans=a*b;
else if(c==47)
{
if(b!=0)ans=a/b;
else
{
printf("Divided by zero!");
return 0;
}
}
if(c!=43&&c!=45&&c!=34&&c!=47)
{
printf("Invalid operator!");
return 0;
}
printf("%d",ans);
return 0;
}
by _Haoomff_ @ 2022-05-15 13:58:15
@Reproduter 乘的ASCII码是42,不是35
by Futaba_Shinaraku @ 2022-05-15 13:59:16
@Haoomff Thx_
(没背ascii 网图事糊的(悲
by Futaba_Shinaraku @ 2022-05-15 14:00:16
已AC
by HarunluoON @ 2022-05-15 14:17:40
其实可以直接这样子'*'
使用的 . . .
背ASCII表不是非常重要
by 123uuu @ 2022-10-22 17:36:55
#include<bits/stdc++.h>
using namespace std;
int main () {
int a,b,c;
char f;
cin>>a>>b>>f;
if(f=='+'){
cout<<a+b;
}
else if(f=='-'){
cout<<a-b;
}
else if(f=='*'){
cout<<a*b;
}
else if(f=='/'){
if(b==0){
cout<<"Divided by zero!";
}
else cout<<a/b;
}
else cout<<"Invalid operator!";
return 0;
}
by hang2023 @ 2023-04-22 18:58:37
ASCII 码错误。
您不需要进行背 ASCII 码,直接使用字符即可。
将 ASCII 码替换成 '+'
,'-'
,'*'
,'/'
即可。