SRM 397 DIV 2 [250]
2008-04-25 17:34
369 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<string>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<map>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class BreakingTheCode
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string decodingEncoding(string code,string message)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string res;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
string aa[]=...{"01","02","03","04","05","06","07","08","09","10","11","12","13","14",
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
"15","16","17","18","19","20","21","22","23","24","25","26"};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
map<string,char> a;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
map<char,string> b;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
for (int i=0;i<26;++i)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
a[aa[i]]=code[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
b[code[i]]=aa[i];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (message[0]>='0'&& message[0]<='2')...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i=0;i!=message.size();i+=2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
res+=a[message.substr(i,2)];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i=0;i!=message.size();++i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
res+=b[message[i]];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return res;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
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 | ||||||||||||
| ||||||||||||
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) | ||||||||||||
| ||||||||||||
1) | ||||||||||||
| ||||||||||||
2) | ||||||||||||
| ||||||||||||
3) | ||||||||||||
|
相关文章推荐
- TopCoder算法竞赛题4:SRM 148 DIV 2, 250-point
- TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%
- TopCoder 250 points 10-SRM 148 DIV 2 167.20/250 66.88%
- TopCoder 250 points 13-SRM 150 DIV 1 82.63/250 33.05%
- TopCoder 250 points 14-SRM 150 DIV 2 86.25/250 34.50%
- TopCoder 250 points 19-SRM 153 DIV 1 84.72/250 33.89%
- SRM 573 250 DIV2
- SRM 544 DIV 2 250
- tc-SRM-626-DIV1-250
- topcoder srm 610 div2 250
- Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索
- SRM 599 div2 250 500
- Topcoder SRM 641 Div1 250(另辟蹊径,排除法)
- 竞赛图的得分序列 (SRM 717 div 1 250)
- TopCoder 250 points 3-SRM 145 DIV 1 84.71/250 33.88%
- TopCoder 250 points 15-SRM 151 DIV 1 121.73/250 48.69%
- TopCoder 250 points 20-SRM 153 DIV 2 216.58/250 86.63%
- SRM 572 250 DIV2
- TopCoder 300 points 24-SRM 155 DIV 2 75/250 30%
- SRM 622 div1 250