没什么好说的,锻炼编程能力,注意善用scanf :)
1 #include <cstdio>
2 using namespace std;
3
4 int N;
5 double a[260];
6
7 int main()
8 {
9 #ifndef ONLINE_JUDGE
10 freopen("537.in","r",stdin);
11 freopen("537.out","w",stdout);
12 #endif
13
14 scanf("%d",&N);
15 getchar();
16
17 for(int i=1;i<=N;i++){
18 a['U']=a['I']=a['P']=0.0;
19 for(int j=0;j<=1;j++){
20 char last=getchar(),now;
21 while((now=getchar())!='=')last=now;
22 scanf("%lf%c",&a[last],&now);
23 switch(now){
24 case 'm':
25 a[last]/=1000.0;
26 break;
27 case 'k':
28 a[last]*=1000.0;
29 break;
30 case 'M':
31 a[last]*=1000000.0;
32 break;
33 }
34 }
35
36 printf("Problem #%d\\n",i);
37
38 if(a['U']&&a['I'])
39 printf("P=%.2lfW",a['U']*a['I']);
40 else if(a['U']&&a['P'])
41 printf("I=%.2lfA",a['P']/a['U']);
42 else if(a['I']&&a['P'])
43 printf("U=%.2lfV",a['P']/a['I']);
44 printf("\\n\\n");
45 }
46
47 fclose(stdin);
48 fclose(stdout);
49 return 0;
50 }
51