UVA之537 - Artificial Intelligence?

 Artificial Intelligence? 

Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understand the problem first!

So they don‘t state a problem like ``U=10V, I=5A, P=?" but rather like ``You have an electrical circuit that contains a battery with a voltage of U=10V and a light-bulb. There‘s an electrical current of I=5A through the bulb. Which power is generated
in the bulb?
".

However, half of the pupils just don‘t pay attention to the text anyway. They just extract from the text what is given: U=10V, I=5A. Then they think: ``Which formulae do I know? Ah yes, P=U*I. Therefore P=10V*5A=500W. Finished."

OK, this doesn‘t always work, so these pupils are usually not the top scorers in physics tests. But at least this simple algorithm is usually good enough to pass the class. (Sad but true.)

Today we will check if a computer can pass a high school physics test. We will concentrate on the P-U-I type problems first. That means, problems in which two of power, voltage and current are given and the third is wanted.

Your job is to write a program that reads such a text problem and solves it according to the simple algorithm given above.

Input

The first line of the input file will contain the number of test cases.

Each test case will consist of one line containing exactly two data fields and some additional arbitrary words. A data field will be of the form I=xAU=xV or P=xW, where x is a real number.

Directly before the unit (AV or W) one of the prefixes m (milli), k (kilo) and M (Mega) may also occur. To summarize it: Data fields adhere to the following grammar:

DataField ::= Concept ‘=‘ RealNumber [Prefix] Unit
Concept   ::= ‘P‘ | ‘U‘ | ‘I‘
Prefix    ::= ‘m‘ | ‘k‘ | ‘M‘
Unit      ::= ‘W‘ | ‘V‘ | ‘A‘

Additional assertions:

  • The equal sign (`=‘) will never occur in an other context than within a data field.
  • There is no whitespace (tabs,blanks) inside a data field.
  • Either P and UP and I, or U and I will be given.

Output

For each test case, print three lines:

  • a line saying ``Problem #k" where k is the number of the test case
  • a line giving the solution (voltage, power or current, dependent on what was given), written without a prefix and with two decimal places as shown in the sample output
  • a blank line

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

Miguel A. Revilla

1999-01-11

【题意】:
根据P = U * I公式进行计算。
输入一行字符串,其中给出P,U,I三个变量的任意两个值求出第三个值。
【代码】:

[cpp] view
plain
copy

  1. <span style="font-style: normal;">/*********************************
  2. *   日期:2013-4-28
  3. *   作者:SJF0115
  4. *   题号: 题目537 - Artificial Intelligence?
  5. *   来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=478
  6. *   结果:AC
  7. *   来源:UVA
  8. *   总结:
  9. **********************************/
  10. #include<stdio.h>
  11. #include<string.h>
  12. int main (){
  13. int i,j,Case,index=1;
  14. double P,I,U,c;
  15. char str[1001];
  16. //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);
  17. while(scanf("%d\n",&Case) != EOF){
  18. while(Case--){
  19. P = 0;
  20. I = 0;
  21. U = 0;
  22. c = 1;
  23. gets(str);
  24. for(i = 0;i < strlen(str);){
  25. //P
  26. if(str[i] == ‘P‘ && str[i+1] == ‘=‘){
  27. i += 2;
  28. //提取小数点前数据
  29. while(str[i] >= ‘0‘ && str[i] <= ‘9‘){
  30. P = P * 10 + str[i] - ‘0‘;
  31. i++;
  32. }
  33. //提取小数点后数据
  34. if(str[i] == ‘.‘){
  35. i++;
  36. while(str[i] >= ‘0‘ && str[i] <= ‘9‘){
  37. c *= 0.1;
  38. P += c * (str[i] - ‘0‘);
  39. i++;
  40. }
  41. }
  42. c = 1;
  43. if(str[i] == ‘k‘){
  44. P *= 1000;
  45. i++;
  46. }
  47. else if(str[i] == ‘m‘){
  48. P /= 1000;
  49. i++;
  50. }
  51. else if(str[i] == ‘M‘){
  52. P *= 1000000;
  53. i++;
  54. }
  55. }
  56. //U
  57. else if(str[i] == ‘U‘ && str[i+1] == ‘=‘){
  58. i += 2;
  59. //提取小数点前数据
  60. while(str[i] >= ‘0‘ && str[i] <= ‘9‘){
  61. U = U * 10 + str[i] - ‘0‘;
  62. i++;
  63. }
  64. //提取小数点后数据
  65. if(str[i] == ‘.‘){
  66. i++;
  67. while(str[i] >= ‘0‘ && str[i] <= ‘9‘){
  68. c *= 0.1;
  69. U += c * (str[i] - ‘0‘);
  70. i++;
  71. }
  72. }
  73. c = 1;
  74. if(str[i] == ‘k‘){
  75. U *= 1000;
  76. i++;
  77. }
  78. else if(str[i] == ‘m‘){
  79. U /= 1000;
  80. i++;
  81. }
  82. else if(str[i] == ‘M‘){
  83. U *= 1000000;
  84. i++;
  85. }
  86. }
  87. //I
  88. else if(str[i] == ‘I‘ && str[i+1] == ‘=‘){
  89. i += 2;
  90. //提取小数点前数据
  91. while(str[i] >= ‘0‘ && str[i] <= ‘9‘){
  92. I = I * 10 + str[i] - ‘0‘;
  93. i++;
  94. }
  95. //提取小数点后数据
  96. if(str[i] == ‘.‘){
  97. i++;
  98. while(str[i] >= ‘0‘ && str[i] <= ‘9‘){
  99. c *= 0.1;
  100. I += c * (str[i] - ‘0‘);
  101. i++;
  102. }
  103. }
  104. c = 1;
  105. if(str[i] == ‘k‘){
  106. I *= 1000;
  107. i++;
  108. }
  109. else if(str[i] == ‘m‘){
  110. I /= 1000;
  111. i++;
  112. }
  113. else if(str[i] == ‘M‘){
  114. I *= 1000000;
  115. i++;
  116. }
  117. }
  118. i++;
  119. }
  120. //输出
  121. printf("Problem #%d\n",index);
  122. if(P > 0 && I > 0){
  123. printf("U=%.2lfV\n",P / I);
  124. }
  125. else if(P > 0 && U > 0){
  126. printf("I=%.2lfA\n",P / U);
  127. }
  128. else if(U > 0 && I > 0){
  129. printf("P=%.2lfW\n",U * I);
  130. }
  131. printf("\n");
  132. index++;
  133. }
  134. }
  135. return 0;
  136. }
  137. </span>

UVA之537 - Artificial Intelligence?,布布扣,bubuko.com

时间: 2024-12-28 21:12:10

UVA之537 - Artificial Intelligence?的相关文章

UVa 537 - Artificial Intelligence?

题目:再一句话里面有P,I,U中的2个已知量,求第三个未知量.(P=I*U) 分析:字符串.利用'='定位已知量,然后将'='后面的的数字和单位分别读入处理. 说明:注意单位有m,k,M的前缀,以及小数点的处理:每组输出后面有一个空行. #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; char Satz[1000]

UVA Artificial Intelligence?(模拟)

Artificial Intelligence? Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Artificial Intelligence?  Physics teachers in high school often think that problems given as text are more demanding than pure

(转) Artificial intelligence, revealed

Artificial intelligence, revealed Yann LeCunJoaquin Qui?onero Candela It's 8:00 am on a Tuesday morning. You've awoken, scanned the headlines on your phone, responded to an online post, ordered a holiday sweater for your mom, locked up the house, and

Artificial intelligence(AI)

http://blog.jobbole.com/96676/#artificial-intelligence 人工智能(Artificial Intelligence) AIMLBot(Program#):使用 C# 编写的一个小型.快速.兼容标准.易于定制的聊天机器人,基于 AIML (人工智能标记语言 Artificial Intelligence Markup Language). SIML :智能综合智能标记语言(Synthetic Intelligence Markup Languag

POJ 2256 Artificial Intelligence?【字符串处理】

题目链接:http://poj.org/problem?id=2256 Artificial Intelligence? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1323   Accepted: 643 Description Physics teachers in high school often think that problems given as text are more demanding than

Artificial Intelligence Research Methodologies 人工智能研究方法

Computer Science An Overview _J. Glenn Brookshear _11th Edition To appreciate the field of artificial intelligence, it is helpful to understand that it is being pursued along two paths. One is the engineering track in which researchers are trying to

Artificial Intelligence

//**************************************BEST-FS ALRORITHM IN ARTIFICAL INTELLIGENCE************************************** // Created by Clivia_zhou . 2014.7.29 #include <iostream> using namespace std; //define functions //Some function has'n finshie

Artificial Intelligence for Robotics

Artificial Intelligence for Robotics L1 (9/22/2017) L2 (9/22/2017 - ) Clip 4 is to be finished. L3 (9/22/2017) Skip. L4 L5 L6 L7 L8 L9 L10 L11 L12 L13 L14 L15 L16 L17 L18 L19 L20

what is artificial Intelligence

一.what is artificial Intelligence 1.the Intelligence exhibited by machines of software机器或软件所展示的智能 2.The name of the academic field of research学术研究领域的名称 3.How to create computers and computer software that are capable  of intelligent behavior如何创建计算机和计