POJ 2121
http://poj.org/problem?id=2121
一道字符串的转换的题目。
题意:就是把那个英文数字翻译成中文。
思路:首先打表,然后把每一个单独的单词分离出来,在组合相加相乘。
#include <stdio.h>
#include <string.h> struct trans{
char eng[];
int num;
}s[]; int main(){
// freopen("in.txt","r",stdin);
strcpy(s[].eng,"zero"), s[].num = ;
strcpy(s[].eng,"one"), s[].num = ;
strcpy(s[].eng,"two"), s[].num = ;
strcpy(s[].eng,"three"), s[].num = ;
strcpy(s[].eng,"four"), s[].num = ;
strcpy(s[].eng,"five"), s[].num = ;
strcpy(s[].eng,"six"), s[].num = ;
strcpy(s[].eng,"seven"), s[].num = ;
strcpy(s[].eng,"eight"), s[].num = ;
strcpy(s[].eng,"nine"), s[].num = ;
strcpy(s[].eng,"ten"), s[].num= ;
strcpy(s[].eng,"eleven"), s[].num= ;
strcpy(s[].eng,"twelve"), s[].num= ;
strcpy(s[].eng,"thirteen"), s[].num= ;
strcpy(s[].eng,"fourteen"), s[].num= ;
strcpy(s[].eng,"fifteen"), s[].num= ;
strcpy(s[].eng,"sixteen"), s[].num= ;
strcpy(s[].eng,"seventeen"),s[].num= ;
strcpy(s[].eng,"eighteen"), s[].num= ;
strcpy(s[].eng,"nineteen"), s[].num= ;
strcpy(s[].eng,"twenty"), s[].num= ;
strcpy(s[].eng,"thirty"), s[].num= ;
strcpy(s[].eng,"forty"), s[].num= ;
strcpy(s[].eng,"fifty"), s[].num= ;
strcpy(s[].eng,"sixty"), s[].num= ;
strcpy(s[].eng,"seventy"), s[].num= ;
strcpy(s[].eng,"eighty"), s[].num= ;
strcpy(s[].eng,"ninety" ), s[].num= ;
strcpy(s[].eng,"hundred"), s[].num= ;
strcpy(s[].eng,"thousand"), s[].num= ;
strcpy(s[].eng,"million"), s[].num= ;
strcpy(s[].eng,"negative"); s[].num= -;
char a[];
while(gets(a))
{
if(strlen(a)==) break;
char tmp[]={};
int ans=,flog=,sum=,x=;
int len=strlen(a);
for(int i=,k=;i<len;i++)
{
if(a[i]!=' ') tmp[k++]=a[i];
if(a[i]==' '||i==len-){
k=;
flog=;
for(int m=;m<=;m++){
if(strcmp(s[m].eng,tmp)==){
if(m==) {
x=-;
continue;
}
if(m<=) sum+=s[m].num;
if(m==) sum*=s[m].num;
if(m>=) {
ans+=sum*s[m].num;
sum=;
}
break;
}
}
}
if(flog==){
memset(tmp,,sizeof(tmp));
flog=;
}
}
printf("%d\n",(ans+sum)*x);
}
return ;
}
POJ 2121的更多相关文章
- 字符串处理,Poj(2121)
题目链接:http://poj.org/problem?id=2121 差一点就WA哭了,主要是自己傻逼了. 思路: 遇到hundred,sum*100; 但是遇到thouthend,million, ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目分类(转)
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
随机推荐
- linux程序调试命令strace
strace命令用法详解: strace常用来跟踪进程执行时的系统调用和所接收的信号. 在Linux世界,进程不能直接访问硬件设备,当进程需要访问硬件设备(比如读取磁盘文件,接收网络数据等等)时,必须 ...
- Web 安全测试
http://blog.sina.com.cn/s/blog_a1bbddc70101dt12.html http://blog.csdn.net/pdn2000/article/details/64 ...
- mysql sql语句为表批量增加字段
方法一 这里可以使用事务 bagin; //事务开始 alter table em_day_data add f_day_house7 int(11); alter table em_day_data ...
- Linux服务器管理: RPM包
服务安装类型主要分两种: RPM安装和源码包编译安装: 1.RPM包查看: rpm -qa | grep 包名 用chkconfig --list 查看服务自启动命令 只对RPM包安装的服务生效 ...
- shell学习之路:流程控制(if)
1.单分支if条件语句 if [ 条件判断式 ];then 程序 fi 或者 if [ 条件判断式 ] then 程序 fi 注意事项: 1.if语句使用fi结尾,和一般语言使用大括号结尾不同 2.[ ...
- CF461B Appleman and Tree (树DP)
CF462D Codeforces Round #263 (Div. 2) D Codeforces Round #263 (Div. 1) B B. Appleman and Tree time l ...
- c# 获取系统时间
//获取日期+时间DateTime.Now.ToString(); // 2008-9-4 20:02:10DateTime.Now.ToLocalTime().ToStrin ...
- php开发总结
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=shared,mys ...
- 详解CSS中clear属性both、left、right值的含义
前几天一朋友在群里问clear:left的意思,我以为是简单的清除浮动问题,就让他百度"清除浮动",导致中间有点小误会.后来我按照他写的DEMO,发现我自己也没完全理解clear: ...
- 增值税——基础知识
一.增值税的概念 增值税是对从事销售货物或者提供加工.修理修配劳务以及从事进出口货物的单位和个人取得的增值额为课税对象征收的一种税. 增值额是指纳税人在生产.经营或劳务活动中所创造的新增价值,即纳税人 ...