拉拉熊為防止其糖果被竊取,因此把糖果存放入堅固的寶相中,並設定了一組 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)

有急救題~~寫個簡單的程式要交作業@@
文章關鍵字
你要先了解題目後把algorithm 演算法 先用簡單口語寫下來
演算法(邏輯流程) 要有正確 coding 才有用
以前我在米國讀書時 老師要看的是演算法 (有對給50,coding 有對再給50)
先看懂這......有瞭解 的話......再看下例
http://www.trytoprogram.com/cpp-examples/cplusplus-program-encrypt-decrypt-string/

http://kaiching.org/pydoing/cpp-guide/unit-19-decoding.html
1.這裡是手機版
2.自己的作業自己寫
都了解規則了...應該不難寫吧
michaelwangroy wrote:
1.這裡是手機版2.(恕刪)

你怎麼知道是作業!!唉唷~~別這樣啦~就是完全沒有頭緒才上來問
soziwow wrote:
你要先了解題目後把algorithm...(恕刪)


謝謝你的導引!!我再研究一下您貼的貼文~~謝謝你
就字母位置根據數字擺一擺
老師應該有講過
上課不認真喔
for (int i=0; i<strlen(T);i++)
{
int num = atoi(N[i]);
printf("%c", T[num]);
}
printf("\n");
// password_decode.cpp : 定義主控台應用程式的進入點。
//

#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;
}
問程式作業跑到mobile01上問......
好歹去個stackoverflow上PO文。而且別的不說,好歹問程式問題要說出自己試過哪些方法,哪裡不懂,或是再寫的時候哪裡有bug不知如何偵錯等。而不是遇到作業就這樣上來問題,伸手要解答。
那文憑要不要也給解答的網友?現在轉系應該還來得及...



雪夢天 wrote:
for (int i(恕刪)

題外話,就這麼簡單的給解答不大好吧XD。不過建議加個bounds checking,雖然改用clang也可。
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!