//C++版代码 #include <iostream> using namespace std; int main() { int a; while (cin >> a) { string s; cin >> s; if (s == "!") { int sum = 1; for (int i = 1; i <= a; i++) { sum *= i; } cout << sum << endl; } else { int b; cin >> b; if (s == "+") { cout << a + b << endl; } else if (s == "-") { cout << a - b << endl; } else if (s == "*") { cout << a * b << endl; } else if (s == "/") { if (b == 0) cout << "error" << endl; else cout << a / b << endl; } else if (s == "%") { if (b == 0) cout << "error" << endl; else cout << a % b << endl; } } } return 0; } //Java版代码 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int a = sc.nextInt(); String s = sc.next(); if (s.equals("!")) { int sum = 1; for (int i = 1; i <= a; i++) { sum *= i; } System.out.println(sum); } else { int b = sc.nextInt(); switch (s) { case "+": System.out.println(a + b); break; case "-": System.out.println(a - b); break; case "*": System.out.println(a * b); break; case "/": if (b == 0) System.out.println("error"); else System.out.println(a / b); break; case "%": if (b == 0) System.out.println("error"); else System.out.println(a % b); break; default: break; } } } } }