[Logo] Mendo Judge Discussion Board - Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
did someone solve that  XML
Forum Index » Задачи од национални натпревари
Author Message
lupin1998



Joined: 07/08/2014 16:19:24
Messages: 1
Offline

http://mendo.mk/Task.do?id=198
Coins
You have a balance scale and 12 coins (numbered 1, 2, ..., 12), one of which is counterfeit. The counterfeit coin is either lighter or heavier than the other, "normal" coins. Three weightings are performed on the balance scale. Write a program coins, which attempts to identify the counterfeit coin and determines if it is heavier or lighter.



Input
The data for each weighing is given on a line of the standard input in the form: A B C D x E F G H where A, B, C, D, E, F, G and H are the numbers of eight different coins, and x is one of the characters <, > or =, with the following meaning:

< : The total weight of coins A, B, C and D is less than the total weight of coins E, F, G и H.
> : The total weight of coins A, B, C and D is greater than the total weight of coins E, F, G и H.
= : The total weight of coins A, B, C and D is equal to the total weight of coins E, F, G и H.


Output
The program writes to the standard output the number of the counterfeit coin and the character '+', when it is heavier than the others, or the character '–', when it is lighter.

If the data of the three weighings is contradictory the program has to output "impossible".

If the data is not contradictory but is insufficient for determining the number of the counterfeit coin, or if it is heavier or lighter the program has to output "indefinite".



Constraints
Time limit: 1 second
Memory limit: 64 megabytes
can i see your code?
filipmihov



Joined: 08/04/2012 13:55:51
Messages: 1
Offline

#include <iostream>
using namespace std;

int t[3][8];
string f[13][2];

int main()
{ string res = "xxx";
for(int w=0; w<3; w++)
{ for(int j=0; j<4; j++)
cin >> t[w][j];
cin >> res[w];
for(int j=4; j<8; j++)
cin >> t[w][j];
}

for(int c=1; c<=12; c++)
{ f[c][0]=f[c][1]="===";
for(int w=0; w<3; w++)
{ for(int j=0; j<4; j++)
{ int c = t[w][j];
f[c][0][w] = '<';
f[c][1][w] = '>';
}
for(int j=4; j<8; j++)
{ int c = t[w][j];
f[c][0][w] = '>';
f[c][1][w] = '<';
}
}
}

int sol=0;
int fls;
char sgn;
for(int c=1; c<=12; c++)
{ if(f[c][0]==res) { sol++; fls=c; sgn='-'; }
if(f[c][1]==res) { sol++; fls=c; sgn='+'; }
}

if(sol==1) cout << fls << sgn << endl;
if(sol==0) cout << "impossible" << endl;
if(sol>=2) cout << "indefinite" << endl;

return 0;
}
 
Forum Index » Задачи од национални натпревари
Go to:   
Powered by JForum 2.1.8 © JForum Team