UVA 537 Artificial Intelligence?

Source: Internet
Author: User
Artificial Intelligence?

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

So they don't state a problem like ' u=10v, i=5a, p=? "But the rather like ' you had an electrical circuit that contains a BA Ttery 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 of 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 is usually not the top scorers in physics tests. But at least this simple algorithm was usually good enough to pass the class. (Sad but true.)

Today We'll check if a computer can pass a high school physics test. We'll concentrate on the P-u-i type problems first. That's means, problems in which of power, voltage and current are given and the third is wanted.


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

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

Each test case would consist of one line containing exactly the data fields and some additional arbitrary words. A data field would be the of the form I=xa, U=XV or P=XW, where x is a real number.

Directly before the unit (A, V or W) One of the prefixes m (Milli), K (Kilo) and M (Mega) may also occur. To summarize it:data, 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 (' = ') would 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 and I'll be given.

Output For the test case, print three lines:

A line saying "problem #k" where k is the number of the "the" the "test case a" line giving the solution (voltage, power or current, Dependent on what is given), written without a prefix and with both decimal places as shown in the sample output a blank l Ine

Sample Input

3
If The voltage is u=200v and the current was i=4.5a, which power is generated?
A light-bulb yields p=100w and the voltage is u=220v. Compute the current.
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三个变量的任意两个值求出第三个值。
【代码】:
/********************************* * Date: 2013-4-28 * Author: SJF0115 * question number: Title 537-artificial Intelligence? * Source: Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=7&page=show_ problem&problem=478 * Results: AC * Source: UVA * Summary: **********************************/#include <stdio.h> #include &
	lt;string.h> int main () {int i,j,case,index=1;
	Double p,i,u,c;
	Char str[1001];  
	Freopen ("C:\\users\\xiaosi\\desktop\\acm.txt", "R", stdin);
			while (scanf ("%d\n", &case)! = EOF) {while (case--) {P = 0;
			I = 0;
			U = 0;
			c = 1;
			Gets (str);
					for (i = 0;i < strlen (str);) {//p if (str[i] = = ' P ' && str[i+1] = = ' = ') {i + = 2;
						Extract the pre-decimal data while (Str[i] >= ' 0 ' && str[i] <= ' 9 ') {p = p * + str[i]-' 0 ';
					i++; }//Extract decimal point after data if (str[i] = = '. ')
						{i++; 
							while (Str[i] >= ' 0 ' && str[i] <= ' 9 ') {C *= 0.1;
							P + = c * (str[i]-' 0 '); i++;
					}} c = 1;
						if (str[i] = = ' k ') {P *= 1000;
					i++;
						} else if (str[i] = = ' m ') {P/= 1000;
					i++; 
						} else if (str[i] = = ' M ') {P *= 1000000;
					i++;
					}}//u else if (str[i] = = ' U ' && str[i+1] = = ') {i + = 2;
						Extract the pre-decimal data while (Str[i] >= ' 0 ' && str[i] <= ' 9 ') {u = u * + str[i]-' 0 ';
					i++; }//Extract decimal point after data if (str[i] = = '. ')
						{i++; 
							while (Str[i] >= ' 0 ' && str[i] <= ' 9 ') {C *= 0.1;
							U + = c * (str[i]-' 0 ');
						i++;
					}} c = 1;
						if (str[i] = = ' k ') {U *= 1000;
					i++;
						} else if (str[i] = = ' m ') {U/= 1000;
					i++; 
						} else if (str[i] = = ' M ') {U *= 1000000;
					i++;
					}}//i else if (str[i] = = ' I ' && str[i+1] = = ' = ') {i + = 2; Extract the pre-decimal data while (Str[i] >= ' 0 ' && str[i] <= ' 9 ') {i = i * + str[i]-' 0 ';
					i++; }//Extract decimal point after data if (str[i] = = '. ')
						{i++; 
							while (Str[i] >= ' 0 ' && str[i] <= ' 9 ') {C *= 0.1;
							I + = c * (str[i]-' 0 ');
						i++;
					}} c = 1;
						if (str[i] = = ' k ') {i *= 1000;
					i++;
						} else if (str[i] = = ' m ') {i/= 1000;
					i++; 
						} else if (str[i] = = ' M ') {i *= 1000000;
					i++;
			}} i++;
			}//Output printf ("Problem #%d\n", index);
			if (P > 0 && I > 0) {printf ("u=%.2lfv\n", p/i);
			} else if (P > 0 && U > 0) {printf ("i=%.2lfa\n", p/u);
			} else if (U > 0 && i > 0) {printf ("p=%.2lfw\n", u * i);
			} printf ("\ n");
		index++;
}} return 0;

	
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.