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

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. 11_什么是sql注入?

    什么是sql注入? --因为后台会把用户输入的插入到后台的sql语句中,来进行sql查询判断用户输入是否存在数据库中,     来验证用户是否合法,就会出现一个问题,用户在做用户验证的时候,在输入框注 ...

  2. MySQL5.6安装(RPM)笔记

    1. 检查MySQL是否安装,如果有安装,则移除(rpm –e 名称)[root@localhost ~]# rpm -qa | grep -i mysqlmysql-libs-xxxxxxxxxx. ...

  3. yum升级mysql

    已安装mysql升级 升级mysql到5.6:下载源wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm安装源:rpm ...

  4. LINUX下SYN攻防战 [转]

    LINUX下SYN攻防战        (一)SYN攻击原理SYN攻击属于DOS攻击的一种,它利用TCP协议缺陷,通过发送大量的半连接请求,耗费服务器CPU和内存资源.SYN攻击聊了能影响主机外,还可 ...

  5. MyCat 入门:漫谈 MyCat 配置系统

    文章首发于[博客园-陈树义],点击跳转到原文<MyCat 入门:漫谈 MyCat 配置系统> 上篇文章<MyCat 启蒙:分布式系统的数据库架构演变>中,我们通过一个项目从零到 ...

  6. VUE环境配置步骤及相关Git Bash命令的使用

    组件式开发中,一定少不了Vue,废话少说,开始进行Vue应用前的关键性配置 备注:(为方便进行配置,提前可以安装Git bash,下载路径——https://git-scm.com/downloads ...

  7. 序列化日期(yyyy-MM-dd hh:mm:ss)

    var getDateFormat = function() { var _date = new Date(); //实例化一个Date对象 var _complete = function(valu ...

  8. Optaplanner - 入门介绍

    OptaPlanner背景 在上一篇里喷了不少水,这一篇准备放点干货:其实也没办法完全干,因为很多预备知道在交待一下.好了,说一下关于OptaPlanner的背景.应用兼容性及其原理. 这一篇先说一下 ...

  9. 多线程编程学习笔记——编写一个异步的HTTP服务器和客户端

    接上文 多线程编程学习笔记——使用异步IO 二.   编写一个异步的HTTP服务器和客户端 本节展示了如何编写一个简单的异步HTTP服务器. 1.程序代码如下. using System; using ...

  10. c# 实现mysql事务

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...