1 条题解
-
0
自动搬运
来自洛谷,原作者为

shame_djj
该怎么办才好呢。。。搬运于
2025-08-24 21:40:46,当前版本为作者最后更新于2019-06-19 21:41:16,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
其实我的思路和楼上楼下都差不多,
那为什么发篇题解呢
我觉得我的代码有两个可取之处
一个是对于cin省去多余符号
来节省码量另一个是边输入边处理
code
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int a, b; char c, ch; int main() { c = getchar(); while (c == ' ') c = getchar(); if (c == '?') { c = getchar(); while (c == ' ') c = getchar(); cin >> a >> ch >> b; if (c == '+') { printf("%.2lf\n", double(b) - double(a)); return 0; } if (c == '-') { printf("%.2lf\n", double(b) + double(a)); return 0; } if (c == '*') { printf("%.2lf\n", double(b) / double(a)); return 0; } if (c == '/') { printf("%.2lf\n", double(b) * double(a)); return 0; } } else { while (c >= '0' && c <= '9') a = a * 10 + c - '0', c = getchar(); while (c == ' ') c = getchar(); ch = c; c = getchar(); while (c == ' ') c = getchar(); if (c == '?') { cin >> c >> b; if (ch == '+') { printf("%.2lf\n", double(b) - double(a)); return 0; } if (ch == '-') { printf("%.2lf\n", double(a) - double(b)); return 0; } if (ch == '*') { printf("%.2lf\n", double(b) / double(a)); return 0; } if (ch == '/') { printf("%.2lf\n", double(a) / double(b)); return 0; } } else { while (c <= '9' && c >= '0') b = b * 10 + c - '0', c = getchar(); if (ch == '+') { printf("%.2lf\n", double(a) + double(b)); return 0; } if (ch == '-') { printf("%.2lf\n", double(a) - double(b)); return 0; } if (ch == '*') { printf("%.2lf\n", double(a) * double(b)); return 0; } if (ch == '/') { printf("%.2lf\n", double(a) / double(b)); return 0; } } } return 0; }希望这篇题解能通过,
也希望大家Noip rp++
加油
- 1
信息
- ID
- 1839
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 3
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者