NC232193. False Coin
描述
| Left pan | Right pan |
1st | 1 2 7 8 13 14 19 20 25 26 31 32 37 38 | 0 4 5 10 11 16 17 22 23 28 29 34 35 40 |
2nd | 0 3 6 11 13 14 16 21 24 29 31 32 34 39 | 2 4 5 7 12 15 20 22 23 25 30 33 38 40 |
3rd | 5 7 9 11 13 14 16 18 20 22 33 35 37 39 | 0 6 8 10 12 15 17 19 21 32 34 36 38 40 |
4th | 0 15 17 19 21 23 25 27 29 31 33 35 37 39 | 14 16 18 20 22 24 26 28 30 32 34 36 38 40 |
输入描述
There are multiple test cases.
For each test case, there are exactly 4 characters in one line, i-th character is the result of i-th weighting, which contains one of the following characters: '<', '>', or '='. It represents the result of the weighting:
'<' means that the weight of coins in the left pan is less than the weight of coins in the right pan,
'>' means that the weight of coins in the left pan is greater than the weight of coins in the right pan,
'=' means that the weight of coins in the left pan is equal to the weight of coins in the right pan.
Input is terminated by end of file.
输出描述
For each case, your program will output one line in following format:
N light/heavy
N is a positive integer: the number of false coins. If coin N is light than true coin, following “light” (without quotation marks), otherwise “heavy” (without quotation marks).
示例1
输入:
>=== ><== >>>> <<<<
输出:
1 heavy 2 heavy 40 light 40 heavy
C 解法, 执行用时: 2ms, 内存消耗: 264K, 提交时间: 2022-06-07 10:11:59
#include <stdio.h> char ss[2][10]={"light","heavy"}; int main(){ char s[5]; int b3[4]={1,3,9,27},i,rs,f; while(scanf("%s",s)!=EOF){ for(i=rs=0,f=1;i<4;++i) if(s[i]!='='){ if(s[i]=='>')rs-=b3[i]; else rs+=b3[i]; f*=-1; } rs*=f; f=rs>0?1:0; if(rs<0)rs=-rs; printf("%d %s\n",rs,ss[f]); } return 0; }