程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Timus 1404. Easy to Hack! 有一個密碼問題

Timus 1404. Easy to Hack! 有一個密碼問題

編輯:C++入門知識

When Vito Maretti writes an important letter he encrypts it. His method is not very reliable but it’s enough to make any detective understand nothing in that letter. Sheriff doesn’t like such state of affairs. He wants to hack the cipher of Vito Maretti and he promises to forget about all of your faults if you do that for him. Detectives will tell you what this cipher looks like. Each word is enciphered separately. Assume an example that consists only of the small Latin letters. At first step every letter is replaced with the corresponding number: a with 0, b with 1, c with 2, ..., z with 25.Then 5 is added to the first number, the first number is added to the second one, the second number – to the third one and so on. After that if some number exceeds 25 it is replaced with the residue of division of this number by 26. And then those numbers are replaced back with the letters. Let’s encipher the word secret.
Step 0.   s   e   c   r   e   t
Step 1.   18  4   2   17  4   19
Step 2.   23  27  29  46  50  69
Step 3.   23  1   3   20  24  17
Step 4.   x   b   d   u   y   r
We’ve got the word xbduyr.

Input

You are given an encrypted word of small Latin letters not longer than 100 characters.

Output

the original word.

Sample

input output
xbduyr
secret

原來簡單的加密也不是什麼難事。做了那麼多加密題,我也可以隨手寫個加密器了。


本題就是一個字符串的操作, 考的是字符串和整形之間的轉換操作:

本題注意:第一個字母小於f的時候,轉換為整數就會小於5了。


#include 
#include 
#include 
#include 
#include 
using namespace std;

void EasytoHack1404()
{
	string s;
	cin>>s;
	vector tmp(s.size());
	for (int i = 0; i < s.size(); i++)
	{
		tmp[i] = s[i] - 'a';
	}
	int t = tmp[0];
	tmp[0] -= 5;
	if (tmp[0] < 0) tmp[0] += 26;
	for (int i = 1; i < tmp.size(); i++)
	{
		int a = tmp[i];
		tmp[i] -= t;
		if (tmp[i] < 0) tmp[i] += 26;
		t = a;
	}
	for (int i = 0; i < tmp.size(); i++)
	{
		cout<


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved