标签:
#include<iostream>
#include<cctype>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
int T, k = 1;
double U, I, P;
cin >> T;
cin.ignore();
string s;
while(T--){
cout << "Problem #" << k++ << endl;
getline(cin,s);
U = I = P = -1;
int i,j;
for(i = 0; i < s.length(); i++){
if(s[i] == ‘=‘){ //判断=号,到数据区
double num = 0,temp = 0;
for(j = i + 1; isdigit(s[j]); j++) //num计算整数部分
num = num*10 + s[j] - ‘0‘;
if(s[j] == ‘.‘){ //如果有小数,则temp计算
int ct = 0;
for(j = j +1; isdigit(s[j]); j++)
temp += (s[j] - ‘0‘)*pow(10.0,-(++ct));
}
num += temp;
if(s[j] == ‘m‘) //判断单位
num /= 1000;
else if(s[j] == ‘k‘)
num *= 1000;
else if(s[j] == ‘M‘)
num *= 1000000;
if(s[i-1] == ‘U‘)
U = num;
else if(s[i-1] == ‘I‘)
I = num;
else if(s[i-1] == ‘P‘)
P = num;
}
}
if(P == -1)
printf("P=%.2fW\n",U*I);
else if(U == -1)
printf("U=%.2fV\n",P/I);
else
printf("I=%.2fA\n",P/U);
cout << endl;
}
return 0;
}
uva 537 - Artificial Intelligence?
标签:
原文地址:http://www.cnblogs.com/yong-hua/p/4650669.html