學術休假-破譯密碼,學術休假破譯
蛋收到了兩串加密的密碼;破解的規則是:現將兩串密碼的數字提取出來,再將上下的數字進行相加,不夠的將用0代替,最後的數字再加上70得到字母的ASCII碼值,最後求出密碼。
例如:
範例輸入:
@#GHt1GG6gB70h)*4^2!*6
%G5=j6%Gg3$g6h0@
1 6 7 0 4 2 6
5 6 3 6 0
=============
6 12 10 6 4 2 6
範例輸出:
LRPLJHL
/* *Copyright (c) 2015,煙台大學電腦學院 *All gight reserved. *檔案名稱:temp.cpp *作者:邵帥 *完成時間:2015年1月18日 *版本號碼:v1.0*/#include<iostream>#include<cstdio>using namespace std;int main(){ int num1[81],num2[81],num3[81];//定義三個數字數組 char str1[81],str2[81];//定義兩個字串數組 int j1,j2,j3,i=0,swa;//swa用於將字元數組強制轉換成ASCII值 j1=j2=0;//初始化j1,j2 gets(str1); gets(str2);//輸入字串!此處用到#include<cstdio>標頭檔 while (str1[i]!='\0')//字串的最後一個字元為'\0',此處用來判斷字元數組是否到達最後位置 { swa=(int)str1[i];//強制轉換 if (swa>=48 && swa<=57) { num1[j1]=(swa-48);//數字數組內儲存篩選出來的數字,數字額ASCII碼值-48得到該數字 // cout<<num1[j1]<<" ";測試資料用 j1++; } i++; } // cout<<endl; i=0;//將i初始化 while (str2[i]!='\0')//同上 { swa=(int)str2[i]; if (swa>=48 && swa<=57) { num2[j2]=swa-48; // cout<<num2[j2]<<" "; j2++; } i++; } // cout<<endl; if (j1>j2)//用於判斷兩個數字數組誰大誰小,小的將用0補充 { for (j2+1; j2<j1; j2++) num2[j2]=0; } if (j2>j1) { for (j1+1; j1<j2; j1++) num1[j1]=0; } // cout<<"===================="<<endl; for (j3=0; j3<j1; j3++)//將兩個數組的數字相加,得到最終的數組num3[] { num3[j3]=num1[j3]+num2[j3]+70; cout<<(char)num3[j3];//強制轉換成字元 }}
運行結果:
@ Mayuko