题意:算出所给的字符串中的关键字符I,P,U,算出结果
思路:自我感觉输入有点蛋疼。。。。。分两个部分输入,详情见代码!!!!!
#include<stdio.h>
#include<string.h>
int main(){
int n, t = 0;
char s[100];
scanf("%d", &n);
while (n--){
int cnt = 0;
double x, y;
char str[2], ss[2];
memset(s, 0, sizeof(s));
while ((s[cnt] = getchar()) != '=')
cnt++;
str[0] = s[cnt - 1];
scanf("%lf", &x);
cnt++;
s[cnt] = getchar();
ss[0] = s[cnt];
if (s[cnt] == 'm' || s[cnt] == 'k' || s[cnt] == 'M'){
if (s[cnt] == 'm')
x /= 1000;
if (s[cnt] == 'k')
x *= 1000;
if (s[cnt] == 'M')
x *= 1000000;
cnt++;
}
while ((s[cnt] = getchar()) != '=')
cnt++;
str[1] = s[cnt - 1];
scanf("%lf", &y);
cnt++;
s[cnt] = getchar();
ss[1] = s[cnt];
if (s[cnt] == 'm' || s[cnt] == 'k' || s[cnt] == 'M'){
if (s[cnt] == 'm')
y /= 1000;
if (s[cnt] == 'k')
y *= 1000;
if (s[cnt] == 'M')
y *= 1000000;
cnt++;
}
printf("Problem #%d\n", ++t);
if ((str[0] == 'U' && str[1] == 'I') || (str[0] == 'I' && str[1] == 'U'))
printf("P=%.2fW\n", x * y);
if (str[0] == 'P' && str[1] == 'U')
printf("I=%.2fA\n", x / (y * 1.0));
if (str[0] == 'U' && str[1] == 'P')
printf("I=%.2fA\n", y / (x * 1.0));
if (str[0] == 'P' && str[1] == 'I')
printf("U=%.2fV\n", x / (y * 1.0));
if (str[0] == 'I' && str[1] == 'P')
printf("U=%.2fV\n", y / (x * 1.0));
printf("\n");
}
return 0;
}