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的更多相关文章

  1. 字符串处理,Poj(2121)

    题目链接:http://poj.org/problem?id=2121 差一点就WA哭了,主要是自己傻逼了. 思路: 遇到hundred,sum*100; 但是遇到thouthend,million, ...

  2. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  3. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  4. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  5. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  6. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  7. POJ题目分类(转)

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  8. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. ASP.NET Padding Oracle Attack EXP

    #!/usr/bin/perl## PadBuster v0.3 - Automated script for performing Padding Oracle attacks# Brian Hol ...

  2. 全选,全不选,反选的js实现

    全选练习       ** 使用复选框上面一个属性判断是否选中                   - checked属性                   - checked=true:选中    ...

  3. MVC缓存OutPutCache学习笔记 (二) 缓存及时化VaryByCustom

    <MVC缓存OutPutCache学习笔记 (一) 参数配置> 本篇来介绍如何使用 VaryByCustom参数来实现缓存的及时化.. 根据数据改变来及时使客户端缓存过期并更新.. 首先更 ...

  4. Loader Generator---loading图片生成器

    if(公司配有专业的设计师) return; Recommend("http://loadergenerator.com/");

  5. iOS 8 牛刀小试

    iOS 8 牛刀小试 1.UIWindow的bounds发生变化(Window本身发生了旋转) iOS 7之前Window的bounds不会随着方向而变化,但是到了iOS 8以后,随着设备方向的旋转, ...

  6. PHP中的位运算与位移运算(其它语言通用)

    /* PHP中的位运算与位移运算 ======================= 二进制Binary:0,1 逢二进1,易于电子信号的传输 原码.反码.补码 二进制最高位是符号位:0为正数,1为负数( ...

  7. PHPCMS V9多站点[站群功能]动态设置与静态设置子站内容URL

    今天我们来讲解下 PHPCMS V9的站群功能的 动态站点与静态站点的配置 站群站点,分为动态站点,和静态站点两种设置方法: 静态的,就是将栏目和内容都了HTML 文件,我们先讲解下,站群的操作: 建 ...

  8. javascript高级程序设计---Event对象二

    鼠标事件 事件种类 鼠标事件指与鼠标相关的事件,主要有以下一些. (1)click事件 click事件当用户在Element节点.document节点.window对象上,单击鼠标(或者按下回车键)时 ...

  9. Triangle leetcode

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  10. 网页兼容浏览器测试工具Multibrowser

    网页兼容性测试工具(MultiBrowser),有firefox,chrome,IE 下载