What is the artificial intelligence?

Source: Internet
Author: User

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 = 10 V, I = 5A, P =?"But rather like''You have an electrical circuit that contains a battery with a voltage of U = 10 V 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 = 10 V, I = 5A. then they think: ''which formulae do I know? Ah yes, P = u * I. Therefore P = 10 V * 5A = 500 W.
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 onP-U-IType 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 abve.

Input

The first line of the input file will contain in 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 =XVOrP =XW,
Where X is a real number.

Directly before the unit (A,VOrW) One of the prefixesM(Milli ),K(Kilo) andM(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.
  • EitherPAndU,PAndI, OrUAndIWill 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

Miguel A. Revilla
2017-01-11
[Question ]:Calculated based on the formula p = u * I.Enter a line of string, which gives any two values of the P, U, And I variables to find the third value.
[Code ]:
/********************************** Date: * Author: sjf0115 * question: Question 537-artificial intelligence? * Source: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & category = 7 & page = show_problem & problem = 478 * result: AC * Source: VA * conclusion: * *********************************/# include <stdio. h> # include <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);) {// PIF (STR [I] = 'P' & STR [I + 1] = ') {I + = 2; // extract the data before the decimal point while (STR [I]> = '0' & STR [I] <= '9 ') {P = p * 10 + STR [I]-'0'; I ++;} // extract the decimal point 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 ++ ;}} // uelse if (STR [I] = 'U' & STR [I + 1] = ') {I + = 2; // extract the data before the decimal point while (STR [I]> = '0' & STR [I] <= '9 ') {u = u * 10 + STR [I]-'0'; I ++;} // extract the decimal point 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 ++ ;}} // ielse if (STR [I] = 'I' & STR [I + 1] = ') {I + = 2; // extract the data before the decimal point while (STR [I]> = '0' & STR [I] <= '9 ') {I = I * 10 + STR [I]-'0'; I ++;} // extract the decimal point 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 ++ ;} // 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.