Question link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 478
Question: It's really frustrating. This question has been done for a long time. The meaning of tat is very simple. It is to describe any two of the voltage U current I power P in a language and find another one.
String Conversion and unit judgment. It's not difficult. It's always in WA. It's just because the header file uses cstdio, and stdio. h is used to restore to normal. It's really, it's just !!!!
Code:
#include <iostream>#include <stdio.h>using namespace std;char s[1000];char *getnum(char *p,double &ans){ ans = 0; while(*p >= '0' && *p <= '9') { ans = *p - '0' + ans * 10; p++; } if(*p == '.') { p++; double quan = 0.1; while(*p >= '0' && *p <= '9') { ans = ans + quan * (*p - '0'); quan *= 0.1; p++; } } return p;}int main(){ int N; cin >> N; cin.get(); double u,i,ap; bool bu,bi,bp; int no = 1; while(N--) { cin.getline(s,1000); char *p = s; bu = 0; bi = 0; bp = 0; while(*p != '\0') { if(*p == '=') { if(*(p - 1) == 'u' || *(p - 1) == 'U') { bu = 1; p++; if(*p >= '0' && *p <= '9') p = getnum(p,u); if(*p == 'm') u *= 0.001; if(*p == 'k') u *= 1000; if(*p == 'M') u *= 1000000; }else if(*(p - 1) == 'i' || *(p - 1) == 'I') { bi = 1; p++; if(*p >= '0' && *p <= '9') p = getnum(p,i); if(*p == 'm') i *= 0.001; if(*p == 'k') i *= 1000; if(*p == 'M') i *= 1000000; }else if(*(p - 1) == 'p' || *(p - 1) == 'P') { bp = 1; p++; if(*p >= '0' && *p <= '9') p = getnum(p,ap); if(*p == 'm') ap *= 0.001; if(*p == 'k') ap *= 1000; if(*p == 'M') ap *= 1000000; } } p++; } cout << "Problem #" << no++ << endl; if(bu && bi) printf("P=%.2lfW\n",u * i); else if(bp && bi) printf("U=%.2lfV\n",ap / i); else if(bu && bp) printf("I=%.2lfA\n",ap / u); cout << endl; } return 0;}
Dream code: http://www.hypo.xyz
What is artificial intelligence?