#include <iostream> using namespace std; int main() { int a, b; char op; while (cin>>a>>op) { // 注意 while 处理多个 case if(op=='!'){ int res=1; for(int i =1;i<=a;i++) res*=i; cout<<res<<endl; continue; }else{ cin>>b; if(op=='+'){ cout<<a+b<<endl; }else if(op=='-'){ cout<<a-b<<endl; }else if(op=='*'){ cout<<a*b<<endl; }else if(op=='/'){ if(b==0){ cout<<"error"<<endl; }else{ cout<<a/b<<endl; } }else if(op=='%'){ if(b==0){ cout<<"error"<<endl; }else{ cout<<a%b<<endl; } } } } } // 64 位输出请用 printf("%lld")
主要难度在输入a,b和op