拉拉熊為防止其糖果被竊取,因此把糖果存放入堅固的寶相中,並設定了一組 10 個字元的密碼 (包含數字與英文字母),
經過特殊的數字規則編碼後,成為另一個 10 個字元的亂碼,然而拉拉熊卻忘記了原來的密碼,口袋中的紙條只有寫下
1.編碼後的亂碼 2.編碼用的數字規則
請寫一個程式,幫心急的拉拉熊找回原始密碼吧 !
<例>
輸入: T= dys5g4w9ep N= 5847360129
dys5g4w9ep 5847360129 ---> #####d#### (第 1 個字元,放在第 6 個位置)
dys5g4w9ep 5847360129 ---> #####d##y# (第 2 個字元,放在第 9 個位置)
dys5g4w9ep 5847360129 ---> ####sd##y# (第 3 個字元,放在第 5 個位置)
dys5g4w9ep 5847360129 ---> ####sd#5y# (第 4 個字元,放在第 8 個位置)
dys5g4w9ep 5847360129 ---> ###gsd#5y# (第 5 個字元,放在第 4 個位置)
dys5g4w9ep 5847360129 ---> ###gsd45y# (第 6 個字元,放在第 7 個位置)
dys5g4w9ep 5847360129 ---> w##gsd45y# (第 7 個字元,放在第 1 個位置)
dys5g4w9ep 5847360129 ---> w9#gsd45y# (第 8 個字元,放在第 2 個位置)
dys5g4w9ep 5847360129 ---> w9egsd45y# (第 9 個字元,放在第 3 個位置)
dys5g4w9ep 5847360129 ---> w9egsd45yp (第 10 個字元,放在第 10 個位置)
因此,輸出 w9egsd45yp
==================================================================
解題語言: CPP: g++ -std=c++14(g++ 7.3.0)
有急救題~~寫個簡單的程式要交作業@@
//
#include "stdafx.h"
#include <conio.h>
#include <string>
#include "password_decode.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 僅有的一個應用程式物件
CWinApp theApp;
using namespace std;
char passwd_scramble[10];
char passwd_order[10];
char passwd_result[10];
char* Get_passwd_key(char* key,char* order);
char* Get_passwd_key(char* key,char* order)
{
int i;
for (i=0;i<10;i++)
{
passwd_result[(order[i]-'0')]=key[i];
}
return passwd_result;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
cout<<"Please input the scramble key:";
cin>>passwd_scramble;
if (strlen(passwd_scramble)!=10)
{
cout<<"Key length is not 10"<<endl;
return 1;
}
cout<<"Please input the order key:";
cin>>passwd_order;
if (strlen(passwd_order)!=10)
{
cout<<"Order length is not 10"<<endl;
return 1;
}
Get_passwd_key(passwd_scramble,passwd_order);
cout<<"Password output:"<<passwd_result<<endl;
_getch();
return nRetCode;
}



























































































