小白书训练-Artificial Intelligence?
来源:互联网 发布:sybase数据库建表语句 编辑:程序博客网 时间:2024/05/24 05:48
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=478
题意:实在是太挫了,这个题目做了好久。TAT,题意很简单,就是用语言描述了电压U电流I功率P中的任意两个,求另一个。
字符串转化以及单位判断嘛,不难,一直在WA,只是因为头文件用的是cstdio,用了stdio.h就恢复正常了,真是的,简直了!!!!
代码:
#include <iostream>#include <stdio.h>using namespace std;char s[1000];char *getnum(char *p,double &ans){ ans = 0; while(*p >= '0' && *p <= '9') { ans = *p - '0' + ans * 10; p++; } if(*p == '.') { p++; double quan = 0.1; while(*p >= '0' && *p <= '9') { ans = ans + quan * (*p - '0'); quan *= 0.1; p++; } } return p;}int main(){ int N; cin >> N; cin.get(); double u,i,ap; bool bu,bi,bp; int no = 1; while(N--) { cin.getline(s,1000); char *p = s; bu = 0; bi = 0; bp = 0; while(*p != '\0') { if(*p == '=') { if(*(p - 1) == 'u' || *(p - 1) == 'U') { bu = 1; p++; if(*p >= '0' && *p <= '9') p = getnum(p,u); if(*p == 'm') u *= 0.001; if(*p == 'k') u *= 1000; if(*p == 'M') u *= 1000000; }else if(*(p - 1) == 'i' || *(p - 1) == 'I') { bi = 1; p++; if(*p >= '0' && *p <= '9') p = getnum(p,i); if(*p == 'm') i *= 0.001; if(*p == 'k') i *= 1000; if(*p == 'M') i *= 1000000; }else if(*(p - 1) == 'p' || *(p - 1) == 'P') { bp = 1; p++; if(*p >= '0' && *p <= '9') p = getnum(p,ap); if(*p == 'm') ap *= 0.001; if(*p == 'k') ap *= 1000; if(*p == 'M') ap *= 1000000; } } p++; } cout << "Problem #" << no++ << endl; if(bu && bi) printf("P=%.2lfW\n",u * i); else if(bp && bi) printf("U=%.2lfV\n",ap / i); else if(bu && bp) printf("I=%.2lfA\n",ap / u); cout << endl; } return 0;}梦续代码:http://www.hypo.xyz
0 0
- 小白书训练-Artificial Intelligence?
- Artificial Intelligence
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence
- Artificial Intelligence
- WHAT IS ARTIFICIAL INTELLIGENCE?
- Artificial Intelligence for Games
- Rethinking artificial intelligence
- 537-- Artificial Intelligence?
- 537 - Artificial Intelligence?
- uva 537 Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- nginx负载均衡配置
- 如何提升自己的技术/能力——兴趣篇
- NYOJ-109 数列转换 AC
- QT5.3的中文乱码问题
- eclipse 手机识别的解决方案
- 小白书训练-Artificial Intelligence?
- 自动化部署MySQL 5.6 步骤
- cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 3 [BattleScene]
- 6147自己写的
- Ubuntu-安装rpm格式文件
- Riak Core Guide 3
- 数据结构 第四章 字符串和多维数组 思维导图
- 和更符合法规和
- Python学习笔记-20141201-Python面向对象编程