题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3220
Abacus is a manual computing device consisting of a frame holding parallel rods strung with movable beads.
How to calculate with Abacus:
Initially, all the upper beads are moved up and all the lower beads are moved down. This represents the number 0. When you add some number, you move upper beads down or move lower beads up. For example, when two lower beads in the first (from right) rod are moved up, it represents the number 2. When one upper bead in the first rod is moved down and three lower beads in the third rod are moved up, it represents 305.
Now with the abacus, your teacher asks you to calculate the sum from number x to number y, both inclusive. After you finish the work, you want to check whether you make any mistake during the calculation.
Input
The first line of the input contains an integer T (T <= 50), indicating the number of cases.
Each case has two parts. The first part in one line consists of two integers x and y (1 <= x <= y <= 1000), indicating the start number and the end number for the sum calculation. The second part is a description for the abacus after you finish the calculation. This part consists of 8 lines and each line consists of 6 characters. Each character is one of ‘o‘ (bead), ‘|‘ (rod) and ‘-‘ (separator). The first two lines represent the upper beads. The third line always consists of ‘-‘, representing the separator. The fourth to the eighth lines represent the lower beads. One column represents one rod. Exactly one ‘|‘ appears in the upper part and one ‘|‘ appears in the lower part in each rod. All the input represents a valid abacus.
Cases are separated by one blank line.
Output
If there is no mistake in the calculation, output "No mistake", else output "Mistake".
Sample Input
3 1 3 ooooo| |||||o ------ |||||o ooooo| oooooo oooooo oooooo 2 4 oooooo |||||| ------ ||||o| oooooo oooo|o oooooo oooooo 20 21 oooooo |||||| ------ ||||oo ooooo| oooooo oooooo oooo|o
Sample Output
No mistake Mistake No mistake
题意:
从x 加到y 的和 是否和算盘上显示的相等,
算盘 上面是代表5
下面是代表 4
代码如下:
#include <cstdio> #include <cstring> int main() { int t; char s[17][17]; scanf("%d", &t); while(t--) { int x, y; scanf("%d%d", &x, &y); int sum=0; for(int i = x; i <= y; i++) sum+=i; for(int i = 0; i < 8; i++) scanf("%s", s[i]); int ans = 0; int i, j; for(i = 0; i < 6; i++) { int tt = 0; if(s[1][i]=='o') tt += 5; for(j = 7; j >= 4; j--) if(s[j][i] == '|') break; tt += (j-3); ans = ans * 10 + tt; } if(ans == sum) printf("No mistake\n"); else printf("Mistake\n"); } return 0; }
ZOJ 3179 Calculate With Abacus(数学啊 )
原文地址:http://blog.csdn.net/u012860063/article/details/44889557