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 ...
随机推荐
- OC-封装
一. set方法和get方法 1. set方法和get方法的使用场合 @public的成员可以被随意赋值,应该使用set方法和get方法来管理成员的访问(类似机场的安检.水 ...
- 404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. 左树的值(9+15=24) /** * Definition for a binary ...
- Linux下vim查看文件名
在vim下编辑时,有时候看不到文件名,不知道编辑的是那个文件,怎么呢,可以按照下面的方法试试. 查看文件名 在正常模式下: :f 或CTRL+G 查看文件的路径 用 :!pwd 可以看当前的详细路径. ...
- Javaee----重新回顾servlet
最近面临找工作,不得不回顾一下java servelt . 发现lz的基本功还是很差 1. 每一个servlet都必须实现servlet接口,GenericServlet是个通用的.不特定于任何协议的 ...
- [原] Intellij IDEA开发Android,祝还在使用eclipse的早日脱离苦海
注: 现在推荐使用Android Studio,以后google在Android Studio上个性差异化的东西越来越多, 所以越早使用Android Studio越好,看看更新文档,使我们开发更方便 ...
- linq学习
最全的linq学习文章: http://www.cnblogs.com/heyuquan/p/Linq-to-Objects.html
- PHP简易聊天室&调试问题
在进入login.php程序之后 <?php error_reporting(E_ALL^E_NOTICE); session_start(); //装载Session库,一定要放在首行 $u ...
- Linux/CentOS配置:使用yum update更新时不升级内核的方法
RedHat/CentOS/Fedora使用 yum update 更新时,默认会升级内核.但有些服务器硬件(特别是组装的机器)在升级内核后,新的内核可能会认不出某些硬件,要重新安装驱动,很麻烦.所以 ...
- iOS设备 屏幕尺寸、操作系统、摄像头像素、发行时间 汇总
设备 硬件尺寸 软件尺寸 精密程度 操作系统 摄像头像素 发行时间 iPhone 4s 640 x 960 320 x 480 2x iOS 5 800万 2011.10.04 iPhone 5 64 ...
- div+css模仿登录界面
我的代码,这种方式形成了遮罩层,遮罩层的"登录"按钮仍可被点击,非我想要的. <!DOCTYPE html> <html lang="en"& ...