UVA537- Artificial Intelligence?

题意:算出所给的字符串中的关键字符I,P,U,算出结果

思路:自我感觉输入有点蛋疼。。。。。分两个部分输入,详情见代码!!!!!

#include<stdio.h>
#include<string.h>

int main(){
	int n, t = 0;
	char s[100];
	scanf("%d", &n);
	while (n--){
		int cnt = 0;	
		double x, y;
		char str[2], ss[2];	
		memset(s, 0, sizeof(s));	
		while ((s[cnt] = getchar()) != '=')		
			cnt++;	
		str[0] = s[cnt - 1];
		scanf("%lf", &x);
		cnt++;
		s[cnt] = getchar();
		ss[0] = s[cnt];
		if (s[cnt] == 'm' || s[cnt] == 'k' || s[cnt] == 'M'){		
			if (s[cnt] == 'm')	
				x /= 1000;	
			if (s[cnt] == 'k')	
				x *= 1000;
			if (s[cnt] == 'M')
				x *= 1000000;
			cnt++;	
		}
		while ((s[cnt] = getchar()) != '=')		
			cnt++;	
		str[1] = s[cnt - 1];
		scanf("%lf", &y);
		cnt++;
		s[cnt] = getchar();
		ss[1] = s[cnt];
		if (s[cnt] == 'm' || s[cnt] == 'k' || s[cnt] == 'M'){		
			if (s[cnt] == 'm')	
				y /= 1000;	
			if (s[cnt] == 'k')	
				y *= 1000;
			if (s[cnt] == 'M')
				y *= 1000000;
			cnt++;	
		}
		printf("Problem #%d\n", ++t);	
		if ((str[0] == 'U' && str[1] == 'I') || (str[0] == 'I' && str[1] == 'U'))	
			printf("P=%.2fW\n", x * y);	
		if (str[0] == 'P' && str[1] == 'U')	
			printf("I=%.2fA\n", x / (y * 1.0));		
		if (str[0] == 'U' && str[1] == 'P')	
			printf("I=%.2fA\n", y / (x * 1.0));		
		if (str[0] == 'P' && str[1] == 'I')	
			printf("U=%.2fV\n", x / (y * 1.0));		
		if (str[0] == 'I' && str[1] == 'P')	
			printf("U=%.2fV\n", y / (x * 1.0));			
		printf("\n");	
	}
	return 0;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值