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

Eason_AC
Remember? / AFOed on 2022.6.14 / 彻底死咯搬运于
2025-08-24 21:34:05,当前版本为作者最后更新于2020-09-18 13:29:02,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
Content
给出整数 的英文写法,求出这个整数 。
规则详见题面。
数据范围:( 个 )。
Solution
题目思路很简单,但要注意细节。
开两个变量 (最终的答案) 和 (当前的计数),边输入一个字符串边一个一个计数,至于对应的操作吗——
-
如果这个字符串是 或者 的话,就直接将 全部计入 里面,并将 清空。
-
否则,将读取到的字符串对应的数字加入到 当中(如果是 就将 乘上 )。
-
注意 的情况,此时应该在最后输出负数。
具体的思路就是这些。
Code
#include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <iostream> using namespace std; string s; long long num, now, f; int main() { f = 1; while(cin >> s) { if(s == "negative") f = -1; if(s == "one") now++; if(s == "two") now += 2; if(s == "three") now += 3; if(s == "four") now += 4; if(s == "five") now += 5; if(s == "six") now += 6; if(s == "seven") now += 7; if(s == "eight") now += 8; if(s == "nine") now += 9; if(s == "ten") now += 10; if(s == "eleven") now += 11; if(s == "twelve") now += 12; if(s == "thirteen") now += 13; if(s == "fourteen") now += 14; if(s == "fifteen") now += 15; if(s == "sixteen") now += 16; if(s == "seventeen") now += 17; if(s == "eighteen") now += 18; if(s == "nineteen") now += 19; if(s == "twenty") now += 20; if(s == "thirty") now += 30; if(s == "forty") now += 40; if(s == "fifty") now += 50; if(s == "sixty") now += 60; if(s == "seventy") now += 70; if(s == "eighty") now += 80; if(s == "ninety") now += 90; if(s == "hundred") now *= 100; if(s == "thousand") num += now * 1000, now = 0; if(s == "million") num += now * 1000000, now = 0; } num += now; printf("%lld", num * f); }Supplement
建议做完这道题目的读者去做一下【P1617】爱与愁的一千个伤心的理由,大意就是将阿拉伯数字转为英文读法。
顺便推广一下我在这道题的题解(
-
- 1
信息
- ID
- 1092
- 时间
- 500~1000ms
- 内存
- 125MiB
- 难度
- 2
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者