image.png

    1. #include <iostream>
    2. #include <string>
    3. using namespace std;
    4. //***********************
    5. //查字典法加密解密
    6. //***********************
    7. string book_code = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    8. string book_decode = "BCDEFGHIJKLMNOPQRSTUVWXYZA1234567890bcdefghijklmnopqrstuvwxyza";
    9. string code(string input){
    10. string result;
    11. for(int i = 0;i<input.size();i++){
    12. for(int j = 0;j<book_code.size();j++){
    13. if(input[i]==book_code[j]){
    14. result+=book_decode[j];
    15. }
    16. }
    17. }
    18. return result;
    19. }
    20. string decode(string input){
    21. string result;
    22. for(int i = 0;i<input.size();i++){
    23. for(int j = 0;j<book_decode.size();j++){
    24. if(input[i]==book_decode[j]){
    25. result+=book_code[j];
    26. }
    27. }
    28. }
    29. return result;
    30. }
    31. int main(){
    32. string str_code;
    33. string str_decode;
    34. while(cin>>str_code){
    35. cin>>str_decode;
    36. string str_result_code = code(str_code);
    37. string str_result_decode = decode(str_decode);
    38. cout<<str_result_code<<endl;
    39. cout<<str_result_decode<<endl;
    40. }
    41. }