日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

对称密码获取(OJ)

發布時間:2025/5/22 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 对称密码获取(OJ) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Catcher是MCA國的情報員,他工作時發現敵國會用一些對稱的密碼進行通信,比如像這些ABBA,ABA,A,123321,但是他們有時會在開始或結束時加入一些無關的字符以防止別國破解。比如進行下列變化?ABBA->12ABBA,ABA->ABAKK,123321->51233214 。因為截獲的串太長了,而且存在多種可能的情況(abaaab可看作是aba,或baaab的加密形式),Cathcer的工作量實在是太大了,他只能向電腦高手求助,你能幫Catcher找出最長的有效密碼串嗎?

輸入:

輸入一個字符串

? ? ?輸出:

返回有效密碼串的最大長度

? ? ?測試樣例:

輸入:ABBAKK

輸出:4


我的源碼:

#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() {int getCommonStrLength(char *pFirstStr, char *pSecondStr);char *str1, *str2;str1 = new char[128];str2 = new char[128];cin.get(str1, 128, '\n');int len = strlen(str1), j = 0;for (int i = len - 1; i >= 0; i--){str2[j++] = str1[i];}if (strlen(str1) == 0 || strlen(str2) == 0){cout << 0 << endl;return -1;}cout << getCommonStrLength(str1, str2) << endl;delete[] str1;delete[] str2;return 0; }int getCommonStrLength(char *pFirstStr, char *pSecondStr) {int len1, len2 = 0, result = 0, con = 0;char *p1 = pFirstStr, *p2 = pSecondStr;len1 = strlen(pFirstStr);len2 = strlen(pSecondStr);if (len1<1 || len2<1)return -1;for (int i = 0; i<len1; i++){int pos = i;for (int j = 0; j<len2; j++){if (p1[pos] == p2[j]){con++;if (result<con)result = con;pos++;}else{con = 0;}}}return result; }

總結

以上是生活随笔為你收集整理的对称密码获取(OJ)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。