UVA-537 Artificial Intelligence?
来源:互联网 发布:程序员女神 赵洁琼 编辑:程序博客网 时间:2024/06/03 20:46
UVA-537 Artificial Intelligence?
题目大意:从一句话中抽取出已知条件,应用公式 P = U * I,求出未知的元素。
Sample Input
3
If 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 #1
P=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;}
0 0
- uva 537 Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- UVA-537 - Artificial Intelligence?
- uva 537 - Artificial Intelligence?
- uva 537 Artificial Intelligence?
- UVA 537 - Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- UVA 537Artificial Intelligence?
- UVA 537 Artificial Intelligence?
- UVa 537: Artificial Intelligence?
- UVA 537 Artificial Intelligence?
- UVA 537 Artificial Intelligence?
- uva 537 Artificial Intelligence?
- uva - 537 - Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- 【DM】设计模式再回顾---简单工厂模式
- idea创建
- 开发安全的web应用程序
- 3.1.3连续分配管理方式
- CC2540/CC2541/CC254x之OSAL消息队列
- UVA-537 Artificial Intelligence?
- nginx负载均衡
- 暑期-dp46道(2)
- spring MVC框架下 前台向java后台传送json字符串数据
- UVA10719Quotient Polynomial
- Android中的ScrollView
- 大素数测试和大数素因子分解
- The MySQL server is running with the --read-only option so it cannot execute this statement
- leetcode——Intersection of Two Arrays II