密文

Homework:

有一个国家的外交信件使用如下方法写成密码:首先颠倒所有的非元音字母段的序列(包括空格和标点符号),然后再把全部信件倒着写。该国总理发出密信如下:

rn.urtbae hes mevi ginoreppe. pesee chaxtret a thekam

 手算一下:

rn.urtbae hes mevi ginoreppe. pesee chaxtret a thekam
mkhut aetretxheci sipo e.peprnegee vma she batr.enar

rane.rtab ehs amv eegenrpep.e opis icehxtertea tuhkm

这是什么鸟语,怎么看不懂

莫非题目题理解错了?

以下程序,解出来如上,@%#*#&@……*#@

ContractedBlock.gifExpandedBlockStart.gifCode
#include <iostream>
#include 
<string>



using namespace std;

bool isVowel(char c)
{
    
if(c == 'a' || c == 'A' || c == 'e' || c == 'E' ||
       c 
== 'i' || c == 'I' || c == 'o' || c == 'O' ||
       c 
== 'u' || c == 'U')
        
return true;
    
else
        
return false;
}

inline 
void exchange(char& a, char& b)
{
    
char temp = a;
    a 
= b;
    b 
= temp;
}


void decipher(string& code)
{
    
int n = code.length();
    
int i = 0, j = n-1;
    
while(i < j)
    {
        
while(isVowel(code[i]))
            
++i;
        
while(isVowel(code[j]))
            
--j;
        
if(i < j)
            exchange(code[i],code[j]);
        
++i;
        
--j;
    }
    i 
= 0;
    j 
= n-1;
    
while(i < j)
    {
        exchange(code[i],code[j]);
        
++i;
        
--j;
    }
}

int main()

{
    
string s = "rn.urtbae hes mevi ginoreppe. pesee chaxtret a thekam";
    decipher(s);
    cout
<<s<<endl;

    
return 0;

}

 

 理解错了,正确如下:

 

ContractedBlock.gifExpandedBlockStart.gifCode
 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 
 6 bool isVowel(char c)
 7 {
 8     if(c == 'a' || c == 'A' || c == 'e' || c == 'E' ||
 9        c == 'i' || c == 'I' || c == 'o' || c == 'O' ||
10        c == 'u' || c == 'U')
11         return true;
12     else
13         return false;
14 }
15 inline void exchange(char& a, char& b)
16 {
17     char temp = a;
18     a = b;
19     b = temp;
20 }
21 void reverse(string& code, int begin, int end)
22 {
23     while(begin < end)
24     {
25         exchange(code[begin],code[end]);
26         ++begin;
27         --end;
28     }
29 }
30 void decipher(string& code)
31 {
32     int n = code.length();
33     int i = 0, j = n-1;
34     int begin=0, end=0;
35     while(begin < n && end < n)
36     {
37         while(isVowel(code[begin]) && begin < n)
38             ++begin;
39         end=begin;
40         while(!isVowel(code[end]) && end < n)
41             ++end;
42         --end;
43         reverse(code,begin,end);
44         begin=end+1;
45     }
46     while(i < j)
47     {
48         exchange(code[i],code[j]);
49         ++i;
50         --j;
51     }
52 }
53 int main()
54 {
55     string s = "rn.urtbae hes mevi ginoreppe. pesee chaxtret a thekam";
56     decipher(s);
57     cout<<s<<endl;
58     return 0;
59 }
60 


转载于:https://www.cnblogs.com/qzchenwl/archive/2008/10/02/1303178.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值