UVA-537 - Artificial Intelligence?

#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;




}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值