栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2971 Give Me the Number

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2971 Give Me the Number

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>using namespace std;#define out(v) cerr << #v << ": " << (v) << endl#define SZ(v) ((int)(v).size())const int maxint = -1u>>1;template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}vector <string> v;int t;char st[100000];int main() { scanf("%d", &t); getchar(); while(t --) { v.clear(); gets(st); int len = strlen(st); string tmp; for(int i = 0; i < len; i ++) { if(st[i] == ' ') { v.push_back(tmp); tmp = ""; continue; } tmp += st[i]; } v.push_back(tmp); len = SZ(v); int rec = 0, ans = 0; for(int i = 0; i < len; i ++) { if(v[i] == "one" && i + 1 < len && v[i + 1] == "hundred") { rec += 100; continue; } if(v[i] == "two" && i + 1 < len && v[i + 1] == "hundred") { rec += 200; continue; } if(v[i] == "three" && i + 1 < len && v[i + 1] == "hundred") { rec += 300; continue; } if(v[i] == "four" && i + 1 < len && v[i + 1] == "hundred") { rec += 400; continue; } if(v[i] == "five" && i + 1 < len && v[i + 1] == "hundred") { rec += 500; continue; } if(v[i] == "six" && i + 1 < len && v[i + 1] == "hundred") { rec += 600; continue; } if(v[i] == "seven" && i + 1 < len && v[i + 1] == "hundred") { rec += 700; continue; } if(v[i] == "eight" && i + 1 < len && v[i + 1] == "hundred") { rec += 800; continue; } if(v[i] == "nine" && i + 1 < len && v[i + 1] == "hundred") { rec += 900; continue; } if(v[i] == "one") rec += 1; if(v[i] == "two") rec += 2; if(v[i] == "three") rec += 3; if(v[i] == "four") rec += 4; if(v[i] == "five") rec += 5; if(v[i] == "six") rec += 6; if(v[i] == "seven") rec += 7; if(v[i] == "eight") rec += 8; if(v[i] == "nine") rec += 9; if(v[i] == "ten") rec += 10; if(v[i] == "eleven") rec += 11; if(v[i] == "twelve") rec += 12; if(v[i] == "thirteen") rec += 13; if(v[i] == "fourteen") rec += 14; if(v[i] == "fifteen") rec += 15; if(v[i] == "sixteen") rec += 16; if(v[i] == "seventeen") rec += 17; if(v[i] == "eighteen") rec += 18; if(v[i] == "nineteen") rec += 19; if(v[i] == "twenty") rec += 20; if(v[i] == "thirty") rec += 30; if(v[i] == "forty") rec += 40; if(v[i] == "fifty") rec += 50; if(v[i] == "sixty") rec += 60; if(v[i] == "seventy") rec += 70; if(v[i] == "eighty") rec += 80; if(v[i] == "ninety") rec += 90; if(v[i] == "thousand") { rec *= 1000; ans += rec; rec = 0; } if(v[i] == "million") { rec *= 1000000; ans += rec; rec = 0; } } ans += rec; printf("%dn", ans); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378625.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号