码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ 3179 Calculate With Abacus(数学啊 )

时间:2015-04-05 18:55:39      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:数学   zoj   

题目链接: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:

  • Each rod is divided into two parts by the separator. The upper part has 1 bead while the lower part has 4 beads.
  • Each rod has its own unit. From right to left, the units are in 1, 10, 100, 1000, ... The leftmost rod is with the largest unit and the rightmost one with the smallest unit(1).
  • Each upper bead represents 5 units of its rod and one lower bead represents 1 unit.

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

Author: HANG, Hang
Contest: The 9th Zhejiang University Programming Contest


题意:

从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(数学啊 )

标签:数学   zoj   

原文地址:http://blog.csdn.net/u012860063/article/details/44889557

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!