陈老师的多校联合 20140809

https://i-blog.csdnimg.cn/blog_migrate/5937300f789dbba7270dabcc70435832.pngcontest/view.action?cid=51408#problem/B

Description

Download as PDF

The government of ``Moderdesh" is planning to enter the digital age and so people of different profession and business are proposing different ways to enter that age successfully. The hardware vendors are saying that we need to provide a laptop for each student, the mobile companies are saying that every children needs to have a mobile phone in his small hand and talk all night long, the multimedia experts are crying for Multimedia University and so on. But very few are crying for the overall improvement of Computer Science education. We do not understand that by being only the consumer of modern digital technologies we cannot enter the real digital age.

\epsfbox{p4854.eps}

Now as a protest, some local computer geeks are planning to digitize the local vegetable and grocery markets in a strange way. The local markets generally use weighing balances as shown in the figure-1 and they use conventional weight sets as shown in figure 2. The computer geeks want to introduce a new type of weight set, where each piece will have the shape of an upper case English alphabet, and strangely Figure 1: The weighing balance weighing a Figure 2: the weights of these pieces will papaya using letter shaped weights. Conventional weight set be related with their ASCII valuess. For example the ASCII value of `A' is 65, which is 10000012 in binary. For each `1' in binary representation a weight of 500 gms will be added and for each `0' in binary representation a weight of 250 gms will be added. So a piece with shape `A' actually weighs (250 * 5 + 2 * 500) gm = 2250 grams. Note that leading zeroes in binary representation are not considered. The geeks believe if others are correct about their ways to enter digital age, they are also correct about digitizing the local markets by introducing new weight sets related to ASCII characters.

Now in this problem you will be given (i) the picture of a weighing scale and the weight pieces that it contains in left pan and in the right pan (ii) You will also be informed which pan is heavier and which pan is lighter (Not necessarily correct). You will have to detect whether the given information is correct or not. If the given information is not correct you will have to rectify the picture and show it in the output.

Input

First line of the input file contains a positive integer T(T$ \le$6000) that denotes the number of test sets. The description of each set of input is given below:

Each set of input is given in a (7 * 18) grid. This grid actually contains the plain text description of a weighing scale. Each location of the grid is either a dot `.' (ASCII value 46) or a front slash `/' (ASCII Value 47) or a back slash `\' (ASCII value 92) or an under score `_' (ASCII value 95) or a pipe `|' (ASCII value 124) an upper case English Alphabet (ASCII value 65 to 90). The (7 * 18) grid is divided into two equal parts by two vertical lines formed with pipe character. The left part denotes the status of left pan and right part denotes the status of the right pan. The bottom of the pan is formed with 6 (six) under score characters and the ropes attached to the pans are formed with front slash and back slash. The weights on both pans are placed just above the row that denotes bottom of the pan and they are left justified. There can be maximum 6 weights on a single pan. There are three possible vertical positioning of the pans (i) Left pan is low and right pan is high (ii) Both pan is in the middle (iii) Left pan is high and right pan is low. If weight of both pan is same then they should be in state (ii), if the left pan is heavier then they should be in status (i) and so on. In the input the pans are always in position (i), (ii) or (iii) but that may not be the correct position according to the weights they contain.

A line containing 18 (eighteen) `-' (minus) signs follows each set of input.

Output

For each set of input produce two or eight line of output. First line should contain the serial of output. If the pans in the input figure are in correct position according to the weights they contain then in the second line print ``The figure is correct." (without the quotes). If the pans are not in correct position then print the weighing balance again in a (7 * 18) grid with the pans in the correct position. Look at the output for sample input for exact formatting.

Sample Input

4 
........||.../\... 
........||../..\.. 
.../\...||./....\. 
../..\..||/G.....\ 
./....\.||\______/ 
/YQYFU.\||........ 
\______/||........ 
------------------
.../\...||........ 
../..\..||........ 
./....\.||.../\... 
/WCGQG.\||../..\.. 
\______/||./....\. 
........||/OYA...\ 
........||\______/ 
------------------
.../\...||........ 
../..\..||........ 
./....\.||.../\... 
/A.....\||../..\.. 
\______/||./....\. 
........||/A.....\ 
........||\______/ 
------------------
........||........ 
.../\...||.../\... 
../..\..||../..\.. 
./....\.||./....\. 
/NQ....\||/FG....\ 
\______/||\______/ 
........||........ 
------------------

Sample Output

Case 1: 
The figure is correct. 
Case 2: 
........||.../\... 
........||../..\.. 
.../\...||./....\. 
../..\..||/OYA...\ 
./....\.||\______/ 
/WCGQG.\||........ 
\______/||........ 
Case 3: 
........||........ 
.../\...||.../\... 
../..\..||../..\.. 
./....\.||./....\. 
/A.....\||/A.....\ 
\______/||\______/ 
........||........ 
Case 4: 
The figure is correct.
题目大意:比较左右两个天平内的字母重量从而判断天平的倾斜方向。重量比较的规则:每个字母都展成ASCII的二进制形式若该位为1就重量就加500,为零就加250,最后把所有字母的重量加起来,两边比较。

解题思路:模拟,没什么好解释的。

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int add(int n)
{
        int sum=0;
        while(n)
        {
            if(n&1)
                sum+=500;
            else
                sum+=250;
            n>>=1;
        }
        return sum;
}
char a[][29]= {  ".../\\...||........",
                 "../..\\..||........",
                 "./....\\.||.../\\...",
                 "/......\\||../..\\..",
                 "\\______/||./....\\.",
                  "........||/......\\",
                  "........||\\______/"
               };

char b[][29]= { "........||........",
                ".../\\...||.../\\...",
                "../..\\..||../..\\..",
                "./....\\.||./....\\.",
                "/......\\||/......\\",
                "\\______/||\\______/",
                "........||........"
               };

char c[][29]= { "........||.../\\...",
                 "........||../..\\..",
                ".../\\...||./....\\.",
                "../..\\..||/......\\",
                "./....\\.||\\______/",
                "/......\\||........",
                "\\______/||........"
               };
char s[10][20];
int main()
{
    int T;
    int tt=0;
    cin>>T;
    while(T--)
    {
        for(int i=0; i<8; i++)
            cin>>s[i];
        char sum1[10],sum2[10];
        memset(sum1,0,sizeof(sum1));
        memset(sum1,0,sizeof(sum2));
        int k1=0,k2=0;
        int ss2=0,ss1=0;
        for(int i=0; i<7; i++)
        {
            for(int j=0; j<9; j++)
            {
                if(s[i][j]>='A'&&s[i][j]<='Z')
                    sum1[k1++]=s[i][j];
            }
            for(int j=9; j<18; j++)
            {
                if(s[i][j]>='A'&&s[i][j]<='Z')
                    sum2[k2++]=s[i][j];
            }

        }
         for(int j=0;j<k1;j++)
            {
                int zhi=sum1[j];
                ss1+=add(zhi);
            }
        for(int j=0;j<k2;j++)
            {
                int zhi=sum2[j];
                ss2+=add(zhi);
            }
        //printf("%d,%d\n",ss1,ss2);
        if(ss1==ss2&&s[1][3]=='/'&&s[1][13]=='/')
        {
            printf("Case %d:\nThe figure is correct.\n",++tt);
            continue;
        }
        if(ss1==ss2)
        {
            for(int i=1; i<=k1; i++)
            {
                b[4][i]=sum1[i-1];
                //printf("%c\n",b[4][i]);
            }
            for(int i=1;i<=k2;i++)
                b[4][i+10]=sum2[i-1];
            printf("Case %d:\n",++tt);
            for(int i=0; i<7; i++)
                printf("%s\n",b[i]);
            for(int i=1; i<=k1; i++)
            {
                b[4][i]='.';
                //printf("%c\n",b[4][i]);
            }
            for(int i=1;i<=k2;i++)
                 b[4][i+10]='.';
            continue;
        }
        if(ss1<ss2&&s[0][3]=='/'&&s[2][13]=='/')
        {
             printf("Case %d:\nThe figure is correct.\n",++tt);
             continue;
        }
        if(ss1>ss2&&s[2][3]=='/'&&s[0][13]=='/')
        {
             printf("Case %d:\nThe figure is correct.\n",++tt);
             continue;
        }
        if(ss1<ss2)
        {
            for(int i=1;i<=k1;i++)
                a[3][i]=sum1[i-1];
            for(int i=1;i<=k2;i++)
                a[5][i+10]=sum2[i-1];
              printf("Case %d:\n",++tt);
             for(int i=0; i<7; i++)
                printf("%s\n",a[i]);
            for(int i=1; i<=k1; i++)
                a[3][i]='.';
            for(int i=1;i<=k2;i++)
                a[5][i+10]='.';
        }
        if(ss1>ss2)
        {
            for(int i=1;i<=k1;i++)
                c[5][i]=sum1[i-1];
            for(int i=1;i<=k2;i++)
                c[3][i+10]=sum2[i-1];
             printf("Case %d:\n",++tt);
             for(int i=0; i<7; i++)
                printf("%s\n",c[i]);
            for(int i=1; i<=k1; i++)
                c[5][i]='.';
            for(int i=1;i<=k2;i++)
                c[3][i+10]='.';
        }
    }
    return 0;
}
/**

........||........
.../\...||.../\...
../..\..||../..\..
./....\.||./....\.
/NQQQQQ\||/FGOOOO\
\______/||\______/
........||........
------------------

.../\...||........
../..\..||........
./....\.||.../\...
/WCCCCC\||../..\..
\______/||./....\.
........||/OYA...\
........||\______/
------------------

........||.../\...
........||../..\..
.../\...||./....\.
../..\..||/GAAA..\
./....\.||\______/
/YQYU..\||........
\______/||........
------------------
**/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值