uva537 - Artificial Intelligence?
来源:互联网 发布:免费注册淘宝店铺 编辑:程序博客网 时间:2024/05/08 14:41
/********************** * Author:FISTY * DATA:2014-12-2 * string * uva 537 * ******************/#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>#include <math.h>#include <ctype.h>using namespace std;#define MAX_N 100double cover(char s, double a){ if(s == 'k'){ a *= 1000; }else if(s == 'M'){ a *= 1000000; }else{ if(s == 'm'){ a *= 0.001; } } return a;} int main(){ int n; int kcase = 0; scanf("%d", &n); char c = getchar(); while(n--){ char str[MAX_N];//存放原字符串 char strU[MAX_N], strI[MAX_N],strP[MAX_N];// 存放值 gets(str); printf("Problem #%d\n", ++kcase); int u = 0,ii = 0,p = 0; for(int i = 0;i < strlen(str); i++){ if(str[i] == 'U' && str[i+1] == '='){ u = 1; int cnt = 0; //str1的下标 char *q = strstr(str, "U="); // 得到U=首地址 for(int j = q-str+2; str[j] != 'V'; j++){ strU[cnt++] = str[j]; } strU[cnt] = '\0'; //for(int k = 0;k < strlen(strU); k++) // putchar(strU[k]); }else if(str[i] == 'I' && str[i+1] == '='){ ii = 1; int cnt = 0; //str1的下标 char *q = strstr(str+2, "I="); // 得到U=首地址 for(int j = q-str+2; str[j] != 'A'; j++){ strI[cnt++] = str[j]; } strI[cnt] = '\0'; }else if(str[i] == 'P' && str[i+1] == '='){ p = 1; int cnt = 0; //str1的下标 char *q = strstr(str, "P="); // 得到U=首地址 for(int j = q-str+2; str[j] != 'W'; j++){ strP[cnt++] = str[j]; } strP[cnt] = '\0'; }else{ continue; } } if(u && ii){ //求P double U,I; int U_len = strlen(strU); int I_len = strlen(strI); //U U = atof(strU); U = cover(strU[U_len-1], U); //I I = atof(strI); I = cover(strI[I_len-1],I); printf("P=%.2lfW\n", U*I); }else if(u && p){ //求I double P,U; int U_len = strlen(strU); int P_len = strlen(strP); U = atof(strU); U = cover(strU[U_len-1],U); P = atof(strP); P = cover(strP[P_len-1], P); printf("I=%.2lfA\n", P/U); }else { if(ii && p){ //求U double I,P; int I_len = strlen(strI); int P_len = strlen(strP); I = atof(strI); I = cover(strI[I_len-1], I); P = atof(strP); P = cover(strP[P_len-1], P); printf("U=%.2lfV\n", P/I); } } printf("\n"); } return 0;}
0 0
- UVA537- Artificial Intelligence?
- UVa537 Artificial Intelligence?
- uva537 - Artificial Intelligence?
- uva537 - Artificial Intelligence?
- UVa537 - Artificial Intelligence?
- UVA537 - Artificial Intelligence?
- UVa537 - Artificial Intelligence?-字符串(混合字符实数输入)-难度3
- uva537 Artificial Intelligence?(字符串转化为浮点数)
- Artificial Intelligence
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence?
- Artificial Intelligence
- Artificial Intelligence
- CentOS 7最小化安装后找不到‘ifconfig’命令——修复小提示
- 5、Service详解(三):远程Service
- Linux系统调用--getitimer/setitimer函数详解
- HDU 2795 Billboard
- C#线程启动时传入参数
- uva537 - Artificial Intelligence?
- MFC 获取字符串的长度方法
- 关于 Android Dex 方法限制的一些总结
- linux中软链接和硬链接的区别与小结
- thrift的安装和使用
- JAVA系统相关
- 经验传承:谈色彩设计方法
- Microsoft .NET Native
- 设置ubuntu 默认不启动图形界面