ZOJ 3179 Calculate with Abacus (math AH)

Source: Internet
Author: User

Title Link: 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 was divided into a parts by the separator. The upper part had 1 bead while the lower part had 4 beads.
    • Each rod have its own unit. From right to left, the units is 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 is moved up and all the lower beads is moved down. This represents the number 0. When you add some number, you move the upper beads down or move lower beads up. For example, when both lower beads in the first and Rod is moved up, it represents the number 2. When one upper bead in the first rod was moved down and three lower beads in the third rod was moved up, it represents 305.

Now with the abacus, your teacher asks you to calculate the sum from number x to number y, both Inclusiv E. After your finish the work, your want to check whether you do any mistake during the calculation.

Input

The first line of the input contains an integer t (T <=), indicating the number of cases.

each case had both parts. The first part on one line consists of integers  x  and  y   (1 <=  x  <=  y  <=, indicating the start number and the end number for the sum calculation. The second part was a description for the abacus after you finish the calculation. This is consists of 8 lines and each line consists of 6 characters. Each character is one of ' o ' (bead), ' | ' (rod) and '-' (separator). The first and the lines represent the upper beads. The third line is 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 is separated by one blank line.

Output

If There is no mistake in the calculation, output "no mistake", else output "mistake".

Sample Input

3ooooo| | | | | | o------| | | | | Oooooo|oooooooooooooooooo2 4oooooo| | | | | | ------|||| O|oooooooooo|ooooooooooooo20 21oooooo| | | | | | ------|||| Ooooooo|oooooooooooooooo|o

Sample Output

No Mistakemistakeno Mistake
Author:Hang , hang
Contest:The 9th Zhejiang University programming Contest


Test instructions

The sums from X to Y are equal to those shown on the abacus,

The abacus above represents 5.

Here is the Representative 4

The code is as follows:

#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 * + tt;        }        if (ans = = sum)            printf ("No mistake\n");        else            printf ("mistake\n");    }    return 0;}


ZOJ 3179 Calculate with Abacus (math AH)

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.