UVA-537 Artificial Intelligence?

Source: Internet
Author: User


http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=22452

This problem test instructions very simple, is in a line of string in a given voltage (U) current (I) power (P) 3 of any of the two let you ask for another, note that the string contains only two equals sign, and after 3 values may have a prefix, that is, there is kv,ma,mw and so on, K for 1000, M stands for 0.001 m for 1000000.

But do feel really worried, did not think of a good way to write out the code is long and messy, submitted always wrong, clearly on a number of situations, or can not think of where the wrong, but the reference to other people's code, it is very concise, or their own problems do less, no experience.

The key or only two equals in the string, then each time you find the equals sign, and then read into the following number, the corresponding conversion can be.

#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring > #include <string> #include <algorithm> #include <string> #include <set> #include < functional> #include <numeric> #include <sstream> #include <stack> #include <map> #include <queue> #define CL (arr, Val) memset (arr, Val, sizeof (arr)) #define LL long long#define INF 0x7f7f7f7f#define LC l,m , Rt<<1#define RC m + 1,r,rt<<1|1#define pi ACOs ( -1.0) #define L (x) (x) << 1#define R (x) (x) <&lt ; 1 | 1#define MID (L, R) (L + R) >> 1#define Min (x, y) (x) < (y)? (x): (y) #define MAX (x, y) (x) < (y)? (y): (x) #define E (x) (1 << (x)) #define IABS (x) (x) < 0? -(x): (x) #define OUT (x) printf ("%i64d\n", x) #define LOWBIT (x) (x) & (-X) #define READ () freopen ("A.txt", "R", stdin) #define Write () freopen ("Dout.txt", "w", stdout), #define N 100005using namespace Std;int main () {  Read ();   int n,k,i,j;   char c;   Double a,w,p,u,i;   scanf ("%d", &n);   GetChar (); for (k=1;k<=n;k++) {p=0;       u=0;i=0;            for (j=0;j<2;j++) {while (scanf ("%c", &c)) if (c== ' = ') break;            scanf ("%lf%c", &a,&c);            U=s;            if (c== ' m ') {w=0.001;scanf ("%c", &c);}            if (c== ' K ') {w=1000;scanf ("%c", &c);}            if (c== ' M ') {w=1000000;scanf ("%c", &c);}            A*=w;            if (c== ' A ') i=a;            if (c== ' V ') u=a;            if (c== ' W ') p=a;       printf ("%.2lf\n", a);       } printf ("Problem #%d\n", k);       if (u&&i) printf ("p=%.2lfw\n", u*i);       if (u&&p) printf ("i=%.2lfa\n", p/u);       if (i&&p) printf ("u=%.2lfv\n", p/i);   printf ("\ n"); } return 0;}



UVA-537 Artificial Intelligence?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.