ACM->uva573

#include <iostream>
#include <string>
#include <cstdio>


using namespace std;


#define INF 1e20


string str;


double p, u, i;


double change(int x)
{
	double res = 0;
	int u = -1, end = -1;
	char ch;
	const double m = 0.001, k = 1000.0, M = 1000000.0;
	
	for (int i = x; i < str.length(); i++)
	{
		if (str[i] != '.' && (str[i] < '0' || str[i] > '9'))
		{
			end = i;
			ch = str[i];
			break;
		}
		
		if (str[i] == '.')
		{
			u = i;
		}
	}
	
	if (u == -1)
	{
		for (int i = x; i < end; i++)
		{
			res = res * 10.0 + (str[i] - '0');
		}
	}
	else
	{
		for (int i = x; i < u; i++)
		{
			res = res * 10.0 + (str[i] - '0');
		}
		
		double sum = 0;
		
		for (int i = end - 1; i > u; i--)
		{
			sum = sum * 0.1 + (str[i] - '0');	
		}
		
		res += sum / 10.0;
	}
	
	if (ch == 'm')
	{
		res *= m;	
	}
	else if (ch == 'k')
	{
		res *= k;	
	}
	else if (ch == 'M')
	{
		res *= M;	
	}
	
	return res;
}


void find_and_change(string &str)
{
	p = u = i = INF;
	
	for (int j = 0; j < str.length(); j++)
	{
		if (str[j] == '=')
		{
			if (str[j - 1] == 'P')
			{
				p = change(j + 1);	
			}
			else if (str[j - 1] == 'U')
			{
				u = change(j + 1);	
			}
			else if (str[j - 1] == 'I')
			{
				i = change(j + 1);	
			}
		}
	}
}


void solve()
{
	if (p == INF)
	{
		printf("P=%.2lfW\n", u * i);	
	}
	else if (u == INF)
	{
		printf("U=%.2lfV\n", p / i);	
	}
	else if (i == INF)
	{
		printf("I=%.2lfA\n", p / u);	
	}
}


void input()
{
	int t, k = 0;
	char ch;
	
	scanf("%d", &t);
	getchar();
	
	while (t--)
	{
		getline(cin, str);
		
		find_and_change(str);
		
		cout << "Problem #" << ++k << endl;
		
		solve();
		
		cout << endl;
	}
}


int main()
{
	input();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值