UVA-537 Artificial Intelligence?
2016-07-15 19:59
323 查看
UVA-537 Artificial Intelligence?
题目大意:从一句话中抽取出已知条件,应用公式 P = U * I,求出未知的元素。
Sample Input
3If the voltage is U=200V and the current is I=4.5A, which power is generated?
A light-bulb yields P=100W and the voltage is U=220V. Compute the current, please.
bla bla bla lightning strike I=2A bla bla bla P=2.5MW bla bla voltage?
Sample Output
Problem #1P=900.00W
Problem #2
I=0.45A
Problem #3
U=1250000.00V
解题思路:对字符逐个判断,遇到 p,u,i 时,判断下一个是否是 = ,如果是,以 lf 读取已知条件的数值,运算后输出结果。
//UVA-537 Artificial Intelligence? #include<iostream> #include<cstdio> #include<cstring> using namespace std; char c; double u,i,p; int count = 1; char str[100000]; int main() { int T; scanf("%d",&T); getchar(); while (T--) { u = 0, i = 0, p = 0; int t = 2; while (t--) { while ((c = getchar()) != '\n' ) { if (c == 'I') { if((c = getchar()) == '=') { scanf("%lf",&i); c = getchar(); if(c == 'm') i = i * 0.001; if(c == 'k') i = i * 1000; if(c == 'M') i = i * 1000000; break; } } if(c == 'P') { if((c = getchar()) != '\n') { scanf("%lf",&p); c = getchar(); if(c == 'm') p = p * 0.001; if(c == 'k') p = p * 1000; if(c == 'M') p = p * 1000000; break; } } if(c == 'U') { if((c = getchar()) != '\n') { scanf("%lf",&u); c = getchar(); if(c == 'm') u = u * 0.001; if(c == 'k') u = u * 1000; if(c == 'M') u = u * 1000000; break; } } } } gets(str); printf("Problem #%d\n",count++); if (u == 0) printf("U=%.2lfV",p/i); if (i == 0) printf("I=%.2lfA",p/u); if (p == 0) printf("P=%.2lfW",u*i); printf("\n\n"); } return 0; }
相关文章推荐
- onclicklistener到底怎么用?
- 简易的C/S系统(实现两个数的和)
- c# 访问SQL Server 其他会话正在使用事务的上下文
- 2016长乐夏令营 Day6
- 自我介绍-决心书
- 开发安全的web应用程序
- Java集合小结
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
- IOS中json字符串原生数据请求&IOS跨平台AES128字符串加解密&AFNetworking框架的简单封装使用
- 软件构架、架构和框架的区别
- linux shell 自动输入y/yes
- js改变style样式和css样式
- OpenCV read video
- HDU 1162 Eddy's picture
- spring MVC框架下前台往java后台传送json数据
- 聪明的质监员(codevs 1138)
- 通过 Docker 化一个博客网站来开启我们的 Docker 之旅
- 归并排序
- SQLite简单理解常用方法与相关类
- dll's .h to dll's .lib