/**********************
* Author:FISTY
* DATA:2014-12-2
* string
* uva 537
* ******************/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <ctype.h>
using namespace std;
#define MAX_N 100
double cover(char s, double a){
if(s == 'k'){
a *= 1000;
}else if(s == 'M'){
a *= 1000000;
}else{
if(s == 'm'){
a *= 0.001;
}
}
return a;
}
int main(){
int n;
int kcase = 0;
scanf("%d", &n);
char c = getchar();
while(n--){
char str[MAX_N];//存放原字符串
char strU[MAX_N], strI[MAX_N],strP[MAX_N];// 存放值
gets(str);
printf("Problem #%d\n", ++kcase);
int u = 0,ii = 0,p = 0;
for(int i = 0;i < strlen(str); i++){
if(str[i] == 'U' && str[i+1] == '='){
u = 1;
int cnt = 0; //str1的下标
char *q = strstr(str, "U="); // 得到U=首地址
for(int j = q-str+2; str[j] != 'V'; j++){
strU[cnt++] = str[j];
}
strU[cnt] = '\0';
//for(int k = 0;k < strlen(strU); k++)
// putchar(strU[k]);
}else if(str[i] == 'I' && str[i+1] == '='){
ii = 1;
int cnt = 0; //str1的下标
char *q = strstr(str+2, "I="); // 得到U=首地址
for(int j = q-str+2; str[j] != 'A'; j++){
strI[cnt++] = str[j];
}
strI[cnt] = '\0';
}else if(str[i] == 'P' && str[i+1] == '='){
p = 1;
int cnt = 0; //str1的下标
char *q = strstr(str, "P="); // 得到U=首地址
for(int j = q-str+2; str[j] != 'W'; j++){
strP[cnt++] = str[j];
}
strP[cnt] = '\0';
}else{
continue;
}
}
if(u && ii){
//求P
double U,I;
int U_len = strlen(strU);
int I_len = strlen(strI);
//U
U = atof(strU);
U = cover(strU[U_len-1], U);
//I
I = atof(strI);
I = cover(strI[I_len-1],I);
printf("P=%.2lfW\n", U*I);
}else if(u && p){
//求I
double P,U;
int U_len = strlen(strU);
int P_len = strlen(strP);
U = atof(strU);
U = cover(strU[U_len-1],U);
P = atof(strP);
P = cover(strP[P_len-1], P);
printf("I=%.2lfA\n", P/U);
}else {
if(ii && p){
//求U
double I,P;
int I_len = strlen(strI);
int P_len = strlen(strP);
I = atof(strI);
I = cover(strI[I_len-1], I);
P = atof(strP);
P = cover(strP[P_len-1], P);
printf("U=%.2lfV\n", P/I);
}
}
printf("\n");
}
return 0;
}
uva537 - Artificial Intelligence?
最新推荐文章于 2021-07-28 14:07:17 发布