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

UVALive 5797解题报告

时间:2015-08-18 12:01:14      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:acm算法   c++   

技术分享



技术分享


The Braille system, designed by Louis Braille in 1825, revolutionized written communication for blind
and visually impaired persons. Braille, a blind Frenchman, developed a tactile language where each
element is represented by a cell with six dot positions, arranged in three rows and two columns. Each
dot position can be raised or not, allowing for 64 di?erent con gurations which can be felt by trained
ngers. The gure below shows the Braille representation for the decimal digits (a black dot indicates
a raised position).
In order to develop a new software system to help teachers to deal with blind or visual impaired
students, a Braille dictionary module is necessary. Given a message, composed only by digits, your job
is to translate it to or from Braille. Can you help?

Input
Each test case is described using three or ve lines. The rst line contains an integer D representing
the number of digits in the message (1  D  100). The second line contains a single uppercase letter
`S‘ or `B‘. If the letter is `S‘, the next line contains a message composed of D decimal digits that your
program must translate to Braille. If the letter is `B‘, the next three lines contain a message composed
of D Braille cells that your program must translate from Braille. Braille cells are separated by single
spaces. In each Braille cell a raised position is denoted by the character `*‘ (asterisk), while a not raised
position is denoted by the character `.‘ (dot).
The last test case is followed by a line containing one zero.

Output
For each test case print just the digits of the corresponding translation, in the same format as the input
(see the examples for further clari cation).

Sample Input
10
S
1234567890
3
B
*. *. **
.. *. ..
.. .. ..
2
S
00
0
Sample Output
*. *. ** ** *. ** ** *. .* .*
.. *. .. .* .* *. ** ** *. **
.. .. .. .. .. .. .. .. .. ..
123
.* .*
** **
.. ..


这题关键是要合理记录盲文信息 合理的方法会大大简化程序 此题并不难 就是有些麻烦的水题。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;


#define MAXN 10000 


char str[10][10]={"011100","100000","101000","110000","110100","100100","111000","111100","101100","011000"};  //6个点 6个记录 
char st[MAXN][10];
int main()
{
    
    int n;
    char a[MAXN],op[5];


    while(scanf("%d",&n)&&n)
    {
        scanf("%s",op);
        if(op[0]==‘S‘)
        {
            scanf("%s",a);
            for(int i = 0; i < 3; i++)
            {
                for(int j = 0; a[j]; j++)
                {
                    int p=a[j]-‘0‘;
                    
                    if(str[p][i*2]==‘1‘) printf("*");//因为每行两个元素 所以乘以2 
                    else printf(".");
                    
                    if(str[p][i*2+1]==‘1‘) printf("*");
                    else printf(".");
                    
                    if(j!=(int)strlen(a)-1)
                        printf(" ");
                }
                printf("\n");
            }


        }
        
        else
        {
            for(int i = 0; i < 3; i++)
            {
                a[0]=‘\0‘;
                while(a[0]==‘\0‘) gets(a);   //一行一行来 
                for(int j = 0,k=0; a[j]; j+=3,k++)
                {


                    if(a[j]==‘*‘) st[k][i*2]=‘1‘;
                    else st[k][i*2]=‘0‘;                //两个为一组记录字符 
                    
                    if(a[j+1]==‘*‘) st[k][i*2+1]=‘1‘;  
                    else st[k][i*2+1]=‘0‘;
                }
            }
            
            for(int i = 0; i < n; i++)
            {
                st[i][6]=‘\0‘;
                for(int j = 0; j < 10; j++)
                {
                    if(strcmp(str[j],st[i])==0)
                    {
                        printf("%d",j);
                        break;
                    }
                }
            }
            printf("\n");
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

UVALive 5797解题报告

标签:acm算法   c++   

原文地址:http://blog.csdn.net/jobsandczj/article/details/47748467

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