fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void tinhtoan(long long a, long long b, char c) {
  6. if (c == '+') {
  7. cout << a + b << "\n";
  8. } else if (c == '-') {
  9. cout << a - b << "\n";
  10. } else if (c == '*') {
  11. cout << a * b << "\n";
  12. } else if (c == '/') {
  13. if (b == 0) {
  14. cout << -1 << "\n";
  15. } else {
  16. cout << a / b << "\n";
  17. }
  18. } else if (c == '%') {
  19. if (b == 0) {
  20. cout << -1 << "\n";
  21. } else {
  22. cout << a % b << "\n";
  23. }
  24. }
  25. }
  26.  
  27. int main() {
  28. ios_base::sync_with_stdio(false);
  29. cin.tie(NULL);
  30.  
  31. int T;
  32. if (cin >> T) {
  33. while (T--) {
  34. long long a, b;
  35. char c;
  36. cin >> a >> b >> c;
  37. tinhtoan(a, b, c);
  38. }
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty