BNUOJ 26190 --------------- In Braille

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 different configurations which can be felt by trained fingers. The figure 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 five lines. The first line contains an integer D representing the number of digits in the message (1D100). 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 clarification).

 

Sample Input

10
S
1234567890
3
B
*. *. **
.. *. ..
.. .. ..
2
S
00
0

Sample Output

*. *. ** ** *. ** ** *. .* .*
.. *. .. .* .* *. ** ** *. **
.. .. .. .. .. .. .. .. .. ..
123
.* .*
** **
.. ..


对应好,输出即可,思路很简单,代码写着麻烦


#include <iostream>
using namespace std;

int main()
{
	int D;
	char c;
	while(cin>>D&&D!=0)
	{
	cin>>c;
	if(c=='S')
	{
		string s;
		cin>>s;
		for(int i=0;i<D;i++)
		{
			if(i)
				cout<<" ";
			switch(s[i])
			{
				case '1':
				case '2':	
				case '5':
				case '8':
					cout<<"*.";
					break;
				case '3':
				case '4':
				case '6':
				case '7':
					cout<<"**";
					break;
				case '9':
				case '0':
					cout<<".*";
					break;
			}
		}
		cout<<endl;
		for(int i=0;i<D;i++)
		{
			if(i)
				cout<<" ";
			switch(s[i])
			{
				case '7':
				case '8':	
				case '0':
					cout<<"**";
					break;
				case '2':
				case '6':
				case '9':
					cout<<"*.";
					break;
				case '1':
				case '3':
					cout<<"..";
					break;
				case '4':
				case '5':
					cout<<".*";
			}	
		}
		cout<<endl;
		for(int i=0;i<D;i++)
		{
			if(i)
				cout<<" ";
			cout<<"..";	
		}
		cout<<endl;
	}
	else if(c=='B')
	{
		int len=3*D;
		string s[len+1];
		for(int i=1;i<=len;i++)
			cin>>s[i];
		for(int i=1;i<=D;i++)
		{
			if(s[i]=="*.")
			{
				if(s[i+D]=="..")
						cout<<1;
				else if(s[i+D]=="*.")
						cout<<2;
				else if(s[i+D]==".*")
						cout<<5;
				else if(s[i+D]=="**")
						cout<<8;
			}	
			else if(s[i]=="**")
			{
				if(s[i+D]=="..")
						cout<<3;	
				else if(s[i+D]=="*.")
						cout<<6;	
				else if(s[i+D]==".*")
						cout<<4;	
				else if(s[i+D]=="**")
						cout<<7;			
			}
			else
			{
				if(s[i+D]=="*.")
						cout<<9;			
				else if(s[i+D]=="**")
						cout<<0;					
			}	
		}
		cout<<endl;
	}
	}
	return 0;	
}



你可能感兴趣的:(BNUOJ 26190 --------------- In Braille)