U E D R , A S I H C RSS

Map연습문제/나휘동

~cpp 
//rule.h
#include <map>
using namespace std;
map <char, char> rule1, rule2, rule3;

void initilize()
{
rule1['b']='1';         rule2['1']='z';         rule3['z']='a'; 
rule1[' ']='2';         rule2['2']='x';         rule3['x']='b'; 
rule1['z']='3';         rule2['3']=' ';         rule3[' ']='c'; 
rule1['a']='4';         rule2['4']='y';         rule3['y']='d'; 
rule1['y']='5';         rule2['5']='a';         rule3['a']='e'; 
rule1['x']='6';         rule2['6']='w';         rule3['w']='f'; 
rule1['i']='7';         rule2['7']='v';         rule3['v']='g'; 
rule1['h']='8';         rule2['8']='u';         rule3['u']='h'; 
rule1['g']='9';         rule2['9']='b';         rule3['b']='i'; 
rule1['\n']='0';        rule2['0']='t';         rule3['t']='j'; 
rule1['c']='!';         rule2['!']='s';         rule3['s']='k'; 
rule1['f']='@';         rule2['@']='c';         rule3['c']='l'; 
rule1['e']='#';         rule2['#']='r';         rule3['r']='m'; 
rule1['d']='$';         rule2['$']='o';         rule3['o']='n'; 
rule1['w']='%';         rule2['%']='d';         rule3['d']='o'; 
rule1['u']='^';         rule2['^']='p';         rule3['p']='p'; 
rule1['v']='&';         rule2['&']='e';         rule3['e']='q'; 
rule1['j']='*';         rule2['*']='q';         rule3['q']='r'; 
rule1['k']='(';         rule2['(']='l';         rule3['l']='s'; 
rule1['l']=')';         rule2[')']='m';         rule3['m']='t'; 
rule1['m']='<';         rule2['<']='f';         rule3['f']='u'; 
rule1['n']='>';         rule2['>']='g';         rule3['g']='v'; 
rule1['o']='?';         rule2['?']='\n';        rule3['\n']='w'; 
rule1['p']='{';         rule2['{']='h';         rule3['h']='x'; 
rule1['t']='}';         rule2['}']='i';         rule3['i']='y'; 
rule1['s']='=';         rule2['=']='j';         rule3['j']='z'; 
rule1['q']='+';         rule2['+']='k';         rule3['k']='2'; 
rule1['r']='-';         rule2['-']='n';         rule3['n']='\n'; 
}

~cpp 
#include <iostream>
#include <string>
#include <vector>
#include "rule.h"

void main()
{
	initilize();
	string source = "wjgydlrtyffworxjbdzyrsybfwlrobffylryjbkyjrtbdcyyrvmbjlsrkugjglrmdcgdarjbjyftr";
	string decoded;
	vector< map<char,char> > rules;
	rules.push_back(rule1);
	rules.push_back(rule2);
	rules.push_back(rule3);

	char ch;
	for ( int i = 0 ; i < source.size() ; i++)
	{
		ch = source[i];
		for ( int rule = 0 ; rule < rules.size() ; rule++ )
			ch = rules[rule][ch];
		decoded += ch;
	}
	
	cout << decoded << endl;		
}


STL실습
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:44
Processing time 0.0104 sec