UVA 537 - Artificial Intelligence?(二)
}
}
//cout << "val.c_str():" << val.c_str() << endl;
double ret = atof(val.c_str())*c;
if(ret == 0){
ret = 0;
}
return ret;
}
void play(){
//cout << buf << endl;
int loc1 = buf.find("=");
//cout << loc1 << endl;
int loc2 = buf.find("=", loc1+1);
//cout << loc2 << endl;
bool useU = false, useI = false, useP = false;
double U = 0, I = 0, P = 0;
switch (buf[loc1-1])
{
case 'U':
U = getValue(loc1);
useU = true;
break;
case 'I':
I = getValue(loc1);
useI = true;
break;
case 'P':
P = getValue(loc1);
useP = true;
break;
}
switch (buf[loc2-1])
{
case 'U':
U = getValue(loc2);
useU = true;
break;
case 'I':
I = getValue(loc2);
useI = true;
break;
case 'P':
P = getValue(loc2);
useP = true;
break;
}
if(!useU){
printf("U=%.2lfV\n", (P/I));
}
else if(!useI){
printf("I=%.2lfA\n", (P/U));
}
else if(!useP){
printf("P=%.2lfW\n", (U*I));
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("537.in", "r", stdin);
freopen("537.out", "w", stdout);
#endif
int n;
scanf("%d", &n);
getchar();
for(int i=0; i
getline(cin, buf);
//cout << buf << endl;
printf("Problem #%d\n", i+1);
play();
p = true;
}
}
#endif