Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

妈蛋,万恶的c++11,万恶的map!

Posted by sunl449554866 at 2014-08-17 00:33:38 on Problem 1051
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

int main()
{
	size_t n;
	string message,code;
	map<string, char> decode;
	decode.insert(pair<string, char>( ".-", 'A' )); decode.insert(pair<string, char>( "-...", 'B' )); decode.insert(pair<string, char>( "-.-.", 'C' )); decode.insert(pair<string,char>( "-..", 'D' ));
	decode.insert(pair<string, char>( ".", 'E' )); decode.insert(pair<string, char>( "..-.", 'F' )); decode.insert(pair<string, char>( "--.", 'G' )); decode.insert(pair<string, char>( "....", 'H' ));
	decode.insert(pair<string, char>("..", 'I')); decode.insert(pair<string, char>( ".---", 'J' )); decode.insert(pair<string, char>( "-.-", 'K' )); decode.insert(pair<string, char>( ".-..", 'L' ));
	decode.insert(pair<string, char>( "--", 'M')); decode.insert(pair<string, char>( "-.", 'N' )); decode.insert(pair<string, char>( "---", 'O' )); decode.insert(pair<string, char>( ".--.", 'P' ));
	decode.insert(pair<string, char>( "--.-", 'Q')); decode.insert(pair<string, char>( ".-.", 'R' )); decode.insert(pair<string, char>( "...", 'S' )); decode.insert(pair<string, char>( "-", 'T' ));
	decode.insert(pair<string, char>( "..-", 'U')); decode.insert(pair<string, char>( "...-", 'V' )); decode.insert(pair<string, char>( ".--", 'W' )); decode.insert(pair<string, char>( "-..-", 'X' ));
	decode.insert(pair<string, char>( "-.--", 'Y')); decode.insert(pair<string, char>( "--..", 'Z' )); decode.insert(pair<string, char>( "..--", '_' )); decode.insert(pair<string, char>( ".-.-", ',' ));
	decode.insert(pair<string, char>("---.", '.')); decode.insert(pair<string, char>( "----", '?' ));
	map<char, string> encode;
	encode.insert(pair<char, string>( 'A', ".-" )); encode.insert(pair<char, string>( 'B', "-..." )); encode.insert(pair<char, string>( 'C', "-.-.")); encode.insert(pair<char, string>( 'D', "-.." ));
	encode.insert(pair<char, string>( 'E', "." )); encode.insert(pair<char, string>( 'F', "..-." )); encode.insert(pair<char, string>( 'G', "--.")); encode.insert(pair<char, string>( 'H', "...." ));
	encode.insert(pair<char, string>( 'I', ".." )); encode.insert(pair<char, string>( 'J', ".---" )); encode.insert(pair<char, string>( 'K', "-.-")); encode.insert(pair<char, string>( 'L', ".-.." ));
	encode.insert(pair<char, string>( 'M', "--" )); encode.insert(pair<char, string>( 'N', "-." )); encode.insert(pair<char, string>( 'O', "---")); encode.insert(pair<char, string>( 'P', ".--." ));
	encode.insert(pair<char, string>( 'Q', "--.-" )); encode.insert(pair<char, string>( 'R', ".-." )); encode.insert(pair<char, string>( 'S', "...")); encode.insert(pair<char, string>( 'T', "-" ));
	encode.insert(pair<char, string>( 'U', "..-" )); encode.insert(pair<char, string>( 'V', "...-" )); encode.insert(pair<char, string>( 'W', ".--")); encode.insert(pair<char, string>( 'X', "-..-" ));
	encode.insert(pair<char, string>( 'Y', "-.--" )); encode.insert(pair<char, string>( 'Z', "--.." )); encode.insert(pair<char, string>( '_', "..--" )); encode.insert(pair<char, string>( ',', ".-.-" ));
	encode.insert(pair<char, string>( '.', "---.")); encode.insert(pair<char, string>( '?', "----" ));
	vector<int> num;
	cin >> n;
	for (size_t j = 1; j <= n; ++j){
		cin >> message;
		cout << j << ": ";
		for (string::iterator i = message.begin(); i != message.end(); ++i){
			string tem = encode[*i];
			num.push_back(tem.length());
			code+=tem;
		}
		string::iterator codei = code.begin();
		for (vector<int>::reverse_iterator i = num.rbegin(); i != num.rend(); ++i){
			string tem(code,codei-code.begin(),*i);
			cout << decode[tem];
			codei += *i;
		}
		cout << endl;
		code.clear();
		num.clear();
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator