POJ Miscellaneous Questions-1013 Counterfeit Dollar

Source: Internet
Author: User
Tags strcmp

Judge the coin problem. This problem does not know how to do, see the other people's discuss have a train of thought.

One, even, both sides are real coins
Two, non-even when, not on the balance are real coins
Third, once thought may be biased, and appear on the side of the light is the real currency.

We can use an array zeros storage must be real, that is, those that appear in the even case; another array of SUS stores suspicion of possible counterfeit money, when it appears on the up, the left side of the coin sus--, the right side of the + +. Down in turn, so that we can judge the positive or negative to determine whether the counterfeit currency is light or heavy, and is considered to be biased, but also appear on the lighter side of SUS naturally will first + +, after-restore to 0.

#include <stdio.h> #include <string.h> #define ABS (x) (x>=0 x:-X) #define MAX (x, y) (x>y?x:y) int sus[13  ];int Zeros[13];int Main () {int t,i,j;scanf ("%d", &t), while (t--) {char left[3][6],right[3][6],status[3][6]; memset (sus,0,sizeof (SUS)); memset (zeros,0,sizeof (zeros)); for (i=0;i<3;i++) {scanf ("%s%s%s", Left[i],right[i], Status[i]);} for (i=0;i<3;i++) {if (strcmp (Status[i], "even") ==0) {for (J=0;j<strlen (Left[i]); j + +) {zeros[left[i][j]-65] = 1; ZEROS[RIGHT[I][J]-65] = 1; }}}for (i=0;i<3;i++) {if (strcmp (Status[i], "up") ==0) {for (J=0;j<strlen (Left[i]); j + +) {sus[left[i][j]-65]--; sus[right[i][j]-65]++;}} else if (strcmp (Status[i], "down") ==0) {for (J=0;j<strlen (Left[i]); j + +) {sus[right[i][j]-65]--;sus[left[i][j]-65] ++;}}} int m =0,maxval = 0;for (i=0;i<13;i++) {if (ABS (Sus[i]) >=maxval && zeros[i]!=1) {maxval = ABS (Sus[i]); m=i;}} if (sus[m]>0) printf ("%c is the counterfeit coin and it was light.\n", m+65), Else printf ("%c is the counterfeit coin and I T is heavy.\n ", m+65);} REturn 0;} 






POJ Miscellaneous Questions-1013 Counterfeit Dollar

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.