字符串处理的题。原题链接

AC代码:

#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
double res[3]; //res[0]~U res[1]~I res[2]~P
char unit[]={'V','A','W'};
char name[]={'U','I','P'};
double solve(int *t,int len)
{
    int pos;
    for(int i=0;i<len;++i)
    {
        pos=i;
        if(t[i]==-1) break;
    }
    if(pos==len-1) pos++;
    int len1=pos,len2=len-pos-1;

    double ans=0.00;
    pos=0;
    for(int i=len1-1;i>=0;--i)
        ans+=pow(10.0,i)*t[pos++];
    pos++;
    for(int i=1;i<=len2;++i)
        ans+=pow(0.1,i)*t[pos++];

    return ans;
}
int main()
{
    int T;
    scanf("%d",&T);
    int cnt=0;
    string str;
    while(T--)
    {
        for(int i=0;i<3;++i) res[i]=-1.0;
        getchar();
        getline(cin,str);
        printf("Problem #%d\n",++cnt);
        for(int i=0;i<str.size();++i)
        {
            if(str[i]!='=') continue;
            int j=i+1,len=0;
            int t[20];
            while(str[j]>='0'&&str[j]<='9'||str[j]=='.')
            {
                if(str[j]=='.') t[len++]=-1;
                else t[len++]=str[j]-'0';
                ++j;
            }
            double x=solve(t,len);
            if(str[j]=='m') x*=0.001;
            else if(str[j]=='k') x*=1000;
            else if(str[j]=='M') x*=1000000;

            if(str[i-1]=='U') res[0]=x;
            else if(str[i-1]=='I') res[1]=x;
            else if(str[i-1]=='P') res[2]=x;
        }
        int pos;
        for(int i=0;i<3;++i)
        {
            if(res[i]==-1) pos=i;
        }
        double ans=0.0;
        if(pos==0) ans=res[2]/res[1];
        else if(pos==1) ans=res[2]/res[0];
        else if(pos==2) ans=res[0]*res[1];
        printf("%c=%.2f%c\n\n",name[pos],ans,unit[pos]);
    }
    return 0;
}

如有不当之处欢迎指出!!

BUNOJ 1011的更多相关文章

  1. SCNU 2015ACM新生赛初赛【1001~1011】个人解题思路

            题目1001:       大意:已知$n$个角色,$m$种怪物种族,$k$个怪物,给出一组角色编号,编号$P_{i}$的角色能肝死编号$i$的怪物,对于给定的一组怪物编号,为了打通关 ...

  2. Ural 1011. Conductors

    1011. Conductors Time limit: 2.0 secondMemory limit: 64 MB Background Everyone making translations f ...

  3. poj 1011

    http://poj.org/problem?id=1011 这是一道POJ的搜索的题目,最开始确实难以理解,但做过一些搜索的题目后,也没那么难了. 大概题意就是,现在有N根木头,要拼成若干根木头,并 ...

  4. (状压) Marriage Ceremonies (lightOJ 1011)

    http://www.lightoj.com/volume_showproblem.php?problem=1011 You work in a company which organizes mar ...

  5. DFS(剪枝) POJ 1011 Sticks

    题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...

  6. HDU 1011 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1011 题目大意:树上取点,先取父亲,再取儿子.每个点,权为w,花费为cost,给定m消费总额,求最大 ...

  7. 1011 最大公约数GCD

    1011 最大公约数GCD 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最大公约数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...

  8. PAT乙级 1011. A+B和C (15)

    1011. A+B和C (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HOU, Qiming 给定区间[-231, 231 ...

  9. 2016年10月26日 星期三 --出埃及记 Exodus 19:10-11

    2016年10月26日 星期三 --出埃及记 Exodus 19:10-11 And the LORD said to Moses, "Go to the people and consec ...

随机推荐

  1. ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in D:\demo\code\yolo\index\index.php on li

    sql语句为:$sql="select count(*) from com where a_id=$v['id']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为:  $ ...

  2. 【转】Vim使用笔记

    http://www.cnblogs.com/jiqingwu/archive/2012/06/14/vim_notes.html 曾经使用了两年多的Vim,手册也翻过一遍.虽然现在不怎么用vim了, ...

  3. Eclipse启动报错[ out of memory error has occurred ]或[ An internal error occurred while showing an internal error ]

    自我总结,有什么需要纠正或更好的方案,请告知,谢谢! 最近上来看到好多同学都遇到了这个问题,之前我也好几次碰到这个问题,很是恼火,什么没干,eclipse一开电脑就卡死了,后来发现不管是新打开ecli ...

  4. springboot(十九):使用Spring Boot Actuator监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  5. pip相关工具使用小结

    最近写taffy的时候用到了两个pip相关的小工具. 一个是pip-review批量更新lib库,一个是pipreqs生成基于项目的requirements.txt. 1. pip相关命令 #更新单个 ...

  6. HTML核心标签之表格标签(一)

    表格的基本语法: <body> <table> <tr><td></td><td></td></tr> ...

  7. RandomAccess接口的使用

    RandomAccess在类Collections的shuffle()方法中的使用:(jdk源码如下) /** * Randomly permute the specified list using ...

  8. BZOJ 3329: Xorequ [数位DP 矩阵乘法]

    3329: Xorequ 题意:\(\le n \le 10^18\)和\(\le 2^n\)中满足\(x\oplus 3x = 2x\)的解的个数,第二问模1e9+7 \(x\oplus 2x = ...

  9. Xposed快速hook关键点

    0x01 导读 工作中,常常需要针对各种app进行快速代码定位,找到代码修改和调试各种功能,就不得不面对xposed来进行一系列快速定位关键代码的问题了.那么问题来了,如何快速找到代码呢? 这里值这针 ...

  10. Missing artifact net.sf.json-lib:json-lib:jar:2.4错误和Eclipse安装Maven插件错误

    微信公众号:compassblog 欢迎关注.转发,互相学习,共同进步! 有任何问题,请后台留言联系! 1.配置Maven项目的pom.xml文件报错 (1).错误描述:Missing artifac ...