#include<iostream>
#include<string>
#include<string.h>
#include<iomanip>
using namespace std;
FILE* s;
double data[5];
char name[5];
void getmark(string& a,double data[],char name[],int cnt){
string::size_type i;
int j = 0;
int k = 0;
for (i = 0; i < a.size(); i++){
if (a[i] == '='){
name[j++] = a[i - 1];
int x = i+1;
double num = 0;
double num2 = 1;
double num3 = 100;
int flag = 1;
int flag2 = 0;
while(a[x] != 'W'&&a[x] != 'V'&&a[x] != 'A'){
if (a[x] == 'm')num *= 0.001;
else if (a[x] == 'M')num *= 1000000;
else if (a[x] == 'k')num *= 1000;
else if (a[x] == '.'){
num2 = (double)(a[++x] - '0') /10;
num += num2;
flag2 = 1;
}
else if (flag2){
num2 = (double)(a[x] - '0') / num3;
num += num2;
num3 *= 10;
}
else{
if (flag){
flag = 0;
}
else{
num *= 10;
}
num += (a[x] - '0');
}
x++;
}
data[k++] = num;
}
}
if ((name[0] == 'U' || name[0] == 'I') && (name[1] == 'U' || name[1] == 'I')){
cout << "Problem #" << cnt+1 << endl;
cout << setiosflags(ios::fixed);
cout << "P=" <<setprecision(2)<< (double)data[0] * data[1] << "W" << endl;
cout << endl;
}
else if (name[0] == 'P'&& name[1] == 'I'){
cout << "Problem #" << cnt+1 << endl;
cout << setiosflags(ios::fixed);
cout << "U=" << setprecision(2) << data[0] / data[1] << "V" << endl;
cout << endl;
}
else if (name[0] == 'I'&& name[1] == 'P'){
cout << "Problem #" << cnt+1 << endl;
cout << setiosflags(ios::fixed);
cout << "U=" << setprecision(2) << data[1] / data[0] << "V" << endl;
cout << endl;
}
else if (name[0] == 'P'&& name[1] == 'U'){
cout << "Problem #" << cnt+1 << endl;
cout << setiosflags(ios::fixed);
cout << "I=" << setprecision(2) << data[0] / data[1] << "A" << endl;
cout << endl;
}
else if (name[0] == 'U'&& name[1] == 'P'){
cout << "Problem #" << cnt+1 << endl;
cout << setiosflags(ios::fixed);
cout << "I=" << setprecision(2) << data[1] / data[0] << "A" << endl;
cout << endl;
}
}
int main(){
int n;
freopen_s(&s,"a.txt","r",stdin);
freopen_s(&s,"b.txt","w",stdout);
while (cin>>n){
getchar();
for (int i = 0; i < n; i++){
string s1;
getline(cin,s1);
memset(data, 0, sizeof(data));
memset(name, 0, sizeof(name));
getmark(s1, data,name,i);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}
UVA-537 - Artificial Intelligence?
最新推荐文章于 2016-10-09 16:49:14 发布