2013秋13级预备队集训练习2 --D - Artificial Intelligence?
来源:互联网 发布:linux网络yum源 编辑:程序博客网 时间:2024/05/16 06:10
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 theP-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 formI=xA, U=xV or P=xW, wherex is a real number.
Directly before the unit (A, V or W) one of the prefixesm (milli), k (kilo) and M (Mega) may also occur. To summarize it: Data fields adhere to the following grammar:
DataField ::= Concept '=' RealNumber [Prefix] UnitConcept ::= '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 U, P and I, or U andI 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
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.00WProblem #2I=0.45AProblem #3U=1250000.00V#include <stdio.h>#include <string.h>int main(){ int i , n , l_s1 , l_s2 , l_s3 , l_s4 , l_s5 , l ; char s1[102] , s2[102] , s3[102] , s4[102] , s5[102] , s[102] ; scanf("%d", &n); getchar(); for(i = 1 ; i <= n ; i++) { for(l_s1 = 0 ; s1[l_s1-1]!='<' ; l_s1++) scanf("%c", &s1[l_s1]); s1[l_s1-1] = '\0'; for(l_s2 = 0 ; s2[l_s2-1]!='>' ; l_s2++) scanf("%c", &s2[l_s2]); s2[l_s2-1] = '\0'; for(l_s3 = 0 ; s3[l_s3-1]!='<' ; l_s3++) scanf("%c", &s3[l_s3]); s3[l_s3-1] = '\0'; for(l_s4 = 0 ; s4[l_s4-1]!='>' ; l_s4++) scanf("%c", &s4[l_s4]); s4[l_s4-1] = '\0'; gets(s5); gets(s); l_s5 = strlen(s5); s5[l_s5] = '\0'; l = strlen(s) ; s[l-3] ='\0'; if(s1[0]!= '\0') printf("%s", s1); if(s2[0]!= '\0') printf("%s", s2); if(s3[0]!= '\0') printf("%s", s3); if(s4[0]!= '\0') printf("%s", s4); if(s5[0]!= '\0') printf("%s", s5); printf("\n"); if(s[0]!='\0') printf("%s", s); if(s4[0]!= '\0') printf("%s", s4); if(s3[0]!= '\0') printf("%s", s3); if(s2[0]!= '\0') printf("%s", s2); if(s5[0]!= '\0') printf("%s", s5); printf("\n"); } return 0;}
- 2013秋13级预备队集训练习2 --D - Artificial Intelligence?
- 2013秋13级预备队集训练习2 --A - Palindromes
- 2013秋13级预备队集训练习1 D - The Decoder
- 2013秋13级预备队集训练习3 --D - Secret Research
- 2013秋13级预备队集训练习4 --D - How Many Points of Intersection?
- 2013秋13级预备队集训练习4 --B - Steps
- 2013秋13级预备队集训练习3 --E - The ? 1 ? 2 ? ... ? n = k problem
- 2013秋13级预备队集训练习2 --C - Automatic Poetry
- 2013秋13级预备队集训练习2 --H - Immediate Decodability
- 2013秋13级预备队集训练习1 A - Hashmat the Brave Warrior
- 2013秋13级预备队集训练习1 B - Back to High School Physics
- 2013秋13级预备队集训练习1 C - Ecological Premium
- 2013秋13级预备队集训练习1 E - Kindergarten Counting Game
- 2013秋13级预备队集训练习1 F - Machined Surfaces
- 2013秋13级预备队集训练习1 G - Rotating Sentences
- 2013秋13级预备队集训练习1 H - Marvelous Mazes
- 2013秋13级预备队集训练习1 I - Triangle Wave
- 2013秋13级预备队集训练习1 J - Hangman Judge
- emgucv mean shift
- Hive create external table partition关联数据文件
- java线程学习--线程同步(二)
- C++中const的用法
- 写在前面
- 2013秋13级预备队集训练习2 --D - Artificial Intelligence?
- 【Qt移植到linux】问题 qt界面无法输入中文,中文不显示,乱码等问题
- 简单的多模块Maven工程
- 52单片机中定时/计数器2的研究 .
- java中各种地址总结
- Java 正则表达式
- 输入框中输入汉字时自动联想相似数据方法使用小结
- VirtualBox更改虚拟硬盘 VDI文件空间大小的方法(特别注意空格和中文)
- 福州大学第十届程序设计竞赛——神庙逃亡——物理题