ZD_source code for problem 2971
题目链接:http://acm.zju.edu.cn/show_problem.php?pid=2971
解题心得:
1,用scanf("%d",&i)接受整型后,再用gets接受带空格的字符串之前要调用getchar将/n滤掉
2,用关键字是字符串的map时要用string类型
#include <stdio.h>
#include <map>
#include <vector>
#include <string>
using namespace std;
map<string,int> times;
map<string,int> str2int;
vector<string> number;
string str[] = {"zero","one","two","three","four","five","six","seven","eight","nine",
"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen","twenty","thirty","forty","fifty","sixty","seventy",
"eighty","ninety"};
void Input()
{
number.clear();
string temp;
char input[128];
gets(input);
int i;
for(i = 0;input[i] != '/0';i++)
{
if(input[i] != ' ')
{
temp += input[i];
}
else
{
number.push_back(temp);
temp = "";
}
}
number.push_back(temp);
}
void Init()
{
int i;
for(i = 0;i <= 20;i++)
str2int[str[i]] = i;
int j;
for(i = 21,j = 30;i < 28;i++,j += 10)
str2int[str[i]] = j;
times[string("and")] = 1;
times[string("hundred")] = 100;
times[string("thousand")] = 1000;
times[string("million")] = 1000000;
}
void Work()
{
int size = number.size();
int i,temp,result;
for(i = 0,temp = 0,result = 0;i < size;i++)
{
if(times.find(number[i]) != times.end())
{
temp *= times[number[i]];
if(number[i] == "million" || number[i] == "thousand")
{
result += temp;
temp = 0;
}
}
else
{
temp += str2int[number[i]];
}
}
result += temp;
printf("%d/n",result);
}
int main(int argc, char* argv[])
{
Init();
int count;
scanf("%d",&count);
getchar();
while(count >= 1)
{
Input();
Work();
count--;
}
return 0;
}
ZD_source code for problem 2971相关推荐
- Code Jam Problem D. GoroSort
题目来源:https://code.google.com/codejam/contest/dashboard?c=975485#s=p3 题目感觉非常不错,有思考的深度! 可以参考官方给出的解析:ht ...
- 安全研究 # Neural Network-based Graph Embedding for Cross-Platform Binary Code Similarity Detection
论文分享<Neural Network-based Graph Embedding for Cross-Platform Binary Code Similarity Detection> ...
- js promises 踩坑 填坑 We have a problem with promises
We have a problem with promises promise 填坑 对于 promise return 与否,结果真的不一样哦. By: Nolan Lawson Published ...
- 对Oracle中索引叶块分裂而引起延迟情况的测试和分析
在版本10.2.0.4未打上相关one-off补丁的情况下,分别对ASSM和MSSM管理模式表空间进行索引分裂测试,经过测试的结论如下: l 在10gr2版本中MSSM方式是不能避免索引分裂引起交易 ...
- how-to-get-a-job-in-deep-learning
http://blog.deepgram.com/how-to-get-a-job-in-deep-learning/ How to Get a Job In Deep Learning 22 SEP ...
- 2018 东北地区大学生程序设计竞赛(ABEHIK)
HDU6500:Problem A. Game with string 题意: 给你一个字符串s以及它的m个子串的首尾位置,现在Alice和 Bob两个人轮流在任一子串的前面或者后面加1个字符,要求加 ...
- 【POJ】【2449】Remmarguts' Date
K短路/A* 经(luo)典(ti) K短路题目= = K短路学习:http://www.cnblogs.com/Hilda/p/3226692.html 流程: 先把所有边逆向,做一遍dijkstr ...
- NDC 2010视频下载:看看其他微软平台程序员们都在做什么
原文地址:<NDC 2010视频下载:看看其他微软平台程序员们都在做什么> NDC(Norwegian Developers Conference,挪威开发者大会)是一年一度的挪威最大的微 ...
- COMP0037 Coursework Investigating Path Planning Algorithms
COMP0037 Coursework 1 Term 2, 2019 "Path Planning in a Known World" Investigating Path Pla ...
- windows ubuntu Android studio安装好启动没反应解决方法
2019独角兽企业重金招聘Python工程师标准>>> 参考:http://blog.csdn.net/qq305013720/article/details/8934152 目前有 ...
最新文章
- Spring Aop实例
- multipath管理存储多路径
- [科普]MinGW vs MinGW-W64及其它
- 三相全桥整流电路_三相桥式全控整流电路
- python奇偶求和_python 判断奇偶并求和,运行过程有错误,希望高手给指导一下。...
- 拳王虚拟项目公社:人人可操作的轻松简单的虚拟资源课程虚拟项目
- 背景铺满整个页面并且自适应
- react 项目实战(二)创建 用户添加 页面 及 fetch请求 json-server db.json -w -p 8000...
- R语言安装bibliometrix包的代码
- 简单的C语言程序介绍(重点理解),超详细基础代码解析
- 【多任务学习-Multitask Learning概述】
- CentOS8 多网卡BondingTeam
- 跑revit计算机硬件要求,什么样的电脑能流畅跑Revit?Revit对电脑配置要求
- HTML/CSS——微信公众号二维码显示效果
- M25F1 4G全网通终端的技术应用
- RK3588 烧写固件
- 7000字,讲透数据指标体系的建设
- CentOS7 使用二进制部署 Kubernetes 1.15-1.17集群(均通用,已经尝试,细心)
- 廖雪峰python教程整理笔记_python小白01廖雪峰python教程笔记
- QGraphicsItem基本图元的添加以及闪烁图元和移动图元的添加