uva 537
2013-08-15 22:13
246 查看
#include <string> #include <iostream> #include <cstdio> using namespace std; int cases; string str; class elements{ public: void set(int pos, string &str){ type = str[pos]; pos += 2; val = 0.0; // init val while(str[pos] >= '0' && str[pos] <= '9'){ val = val * 10 + (str[pos] - '0'); ++pos; } if(str[pos] == '.'){ //if there is a dot ++pos; double k = 10; while(str[pos] >= '0' && str[pos] <= '9'){ val += (str[pos] - '0')/k; k *= 10; ++pos; } } if(str[pos] == 'm' || str[pos] == 'k' || str[pos] == 'M'){ resetVal(pos, str); //reset val } } void resetVal(const int &pos, string &str){ switch(str[pos]){ case 'm': val /= 1000; break; case 'k': val *= 1000; break; case 'M': val *= 1000000; break; } } void output(){ printf("%c=%0.2lf", type, val); switch(type){ case 'U':printf("V"); break; case 'I':printf("A"); break; case 'P':printf("W"); break; } printf("\n"); } double val; //the val char type; //the type }; elements store[3]; int main() { cin >> cases; getchar(); for(int i = 1; i <= cases; i++){ getline(cin, str); int index = 0; int pos = 0; while(index < 2 ){ while(str[pos] != '='){ pos++; } store[index++].set(pos - 1, str); ++pos; } if(index == 2){ for(index = 0; index != 2; index++){ if(store[index].type == 'P') break; } if(index != 2){ pos = 1 - index; if(store[pos].type == 'U'){ store[2].type = 'I'; }else{ store[2].type = 'U'; } store[2].val = store[index].val/store[pos].val; }else{ store[2].type = 'P'; store[2].val = store[0].val * store[1].val; } } printf("Problem #%d\n", i); store[2].output(); printf("\n"); } return 0; }
相关文章推荐
- uva 537 - Artificial Intelligence?
- UVA 537 解题报告
- UVA 537 Artificial Intelligence?
- uva 537
- UVa 537 Artificial Intelligence?
- UVA - 537 Artificial Intelligence?
- UVa 537 Artificial Intelligence?
- Uva 537 Artificial Intelligence?(Java正则表达式)
- UVa537 - Artificial Intelligence?
- UVA 537 字符串中的公式计算字母识别
- UVa 537 - Artificial Intelligence?
- UVA - UVA - 537 Artificial
- UVA537
- UVa537 Artificial Intelligence?
- UVa 537 - Artificial Intelligence?
- UVA之537 - Artificial Intelligence?
- UVA 537 Artificial Intelligence?
- uva 537 - Artificial Intelligence?
- UVa 537 - Artificial Intelligence?解题报告
- uva537