SRM 397 DIV 2 [250]
来源:互联网 发布:部落冲突极速升级数据 编辑:程序博客网 时间:2024/05/16 12:07
#include<string>
#include<map>
using namespace std;
class BreakingTheCode
...{
public:
string decodingEncoding(string code,string message)
...{
string res;
string aa[]=...{"01","02","03","04","05","06","07","08","09","10","11","12","13","14",
"15","16","17","18","19","20","21","22","23","24","25","26"};
map<string,char> a;
map<char,string> b;
for (int i=0;i<26;++i)...{
a[aa[i]]=code[i];
b[code[i]]=aa[i];
}
if (message[0]>='0'&& message[0]<='2')...{
for (int i=0;i!=message.size();i+=2)
res+=a[message.substr(i,2)];
}
else
for (int i=0;i!=message.size();++i)
res+=b[message[i]];
return res;
}
};
Problem Statement
You have been given a secret mission where you must break the enemy's code. You have already figured out that they encode messages using the following method. Each letter between 'a' and 'z', inclusive, is assigned a distinct two-digit number between 01 and 26, inclusive. A message is encoded by simply replacing each letter with its assigned number. For example, if 't' is assigned 20, 'e' is assigned 05 and 's' is assigned 19, then the message "test" is encoded as "20051920". All original messages contain only lowercase letters.
You are given a string code containing the assignment of numbers to letters. The first letter of code is assigned 01, the second is assigned 02 and so on. You are also given a string message which is either an original unencoded message or an encoded message. If you are given an unencoded message, return the encoded version of that message, and if you are given an encoded message, return the original unencoded message.
Definition
Class: BreakingTheCode Method: decodingEncoding Parameters: string, string Returns: string Method signature: string decodingEncoding(string code, string message) (be sure your method is public)Constraints
- code will contain exactly 26 characters. - Each lowercase letter between 'a' and 'z', inclusive, will occur exactly once in code. - message will contain between 1 and 50 characters, inclusive. - message will either contain only lowercase letters ('a'-'z') or only digits ('0'-'9'). - If message contains only digits, it will be a concatenation of two-digit numbers, each between 01 and 26, inclusive.Examples
0)"abcdefghijklmnopqrstuvwxyz"
"test"
Returns: "20051920"Example from the problem statement. Here, the letters are coded in an alphabetical order. 1)
"abcdefghijklmnopqrstuvwxyz"
"20051920"
Returns: "test"Now, we're decoding it. 2)
"qesdfvujrockgpthzymbnxawli"
"mwiizkelza"
Returns: "19242626171202251723"3)
"faxmswrpnqdbygcthuvkojizle"
"02170308060416192402"
Returns: "ahxpwmtvza"
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
- SRM 397 DIV 2 [250]
- SRM 145 DIV 2 250
- SRM 668 DIV 2 VerySecureEncryption 250point
- SRM 667 DIV 2 PointDistance 250-point
- SRM 669 DIV 2 LiveConcert 250-point
- SRM 670 DIV 2 Cdgame 250-point
- 【topcoder SRM 702 DIV 2 250】TestTaking
- SRM 458 Div 2
- SRM 459 DIV 2
- SRM 480 DIV 2
- SRM 527 DIV 2
- SRM 528 DIV 2
- SRM 531 DIV 2
- SRM 533 DIV 2
- SRM 536 DIV 2
- srm 565 div 2
- srm 592 div 2
- SRM 622 DIV 2
- 使用LogKit进行日志操作
- 利用Struts结合Jbuilder7、MySql建立Web站点(1)--连
- One World, One Web——记第十七届万维网大会
- Cocoa with gcc command build without window
- XML在B/S架构开发中的应用
- SRM 397 DIV 2 [250]
- Sql常用函数语句
- win98下配置jsp的运行环境实践
- C#的面试题及答案
- 设计模式(Design Patterns)笔记之二:Adapter
- LVM创建和使用
- Jason Hunter采访
- 制作可执行JAR
- MIDP中的动画