| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一直wa 有什么坑点吗?#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 30;
const int MOD = 1000000007;
const int INF = 2000000000;
const double PI = 3.14159265358979;
const int dir_4r[] = { -1, 1, 0, 0 };
const int dir_4c[] = { 0, 0, -1, 1 };
const int dir_8r[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dir_8c[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
stringstream ss;
string str;
int n, kase;
bool haveP, haveU, haveI;
double valP, valU, valI;
double base;
int main()
{
getline(cin, str);
ss.clear();
ss.str(str);
ss >> n;
kase = 0;
while (n--)
{
haveP = haveU = haveI = false;
getline(cin, str);
ss.clear();
ss.str(str);
while (ss >> str)
{
base = 1;
int len = str.size();
if (len >= 4 && str[1] == '=')
{
if (str[0] == 'P')
{
haveP = true;
if (str[len - 2] == 'm')
base = 0.001;
else if (str[len - 2] == 'k')
base = 1000;
else if (str[len - 2] == 'M')
base = 1000000;
if (base == 1)
str = str.substr(2, len - 3);
else
str = str.substr(2, len - 4);
valP = atof(str.c_str());
valP *= base;
}
else if (str[0] == 'U')
{
haveU = true;
if (str[len - 2] == 'm')
base = 0.001;
else if (str[len - 2] == 'k')
base = 1000;
else if (str[len - 2] == 'M')
base = 1000000;
if (base == 1)
str = str.substr(2, len - 3);
else
str = str.substr(2, len - 4);
valU = atof(str.c_str());
valU *= base;
}
else if (str[0] == 'I')
{
haveI = true;
if (str[len - 2] == 'm')
base = 0.001;
else if (str[len - 2] == 'k')
base = 1000;
else if (str[len - 2] == 'M')
base = 1000000;
if (base == 1)
str = str.substr(2, len - 3);
else
str = str.substr(2, len - 4);
valI = atof(str.c_str());
valI *= base;
}
}
}
if (haveP && haveU)
{
printf("Problem #%d\n", ++kase);
printf("I=%.2fA\n\n", valP / valU);
}
else if (haveP && haveI)
{
printf("Problem #%d\n", ++kase);
printf("U=%.2fV\n\n", valP / valI);
}
else if (haveU && haveI)
{
printf("Problem #%d\n", ++kase);
printf("P=%.2fW\n\n", valU * valI);
}
}
//system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator