简单的初级C++程序编写
将“fly”译成密码“jpc”。编码规律:将字母a变成字母f,即变成其后的第四个字母,x变成b,y变成c,z变成d。提示:用赋初值的方法是c1,c2,c3的值分别为'f'...
将“fly”译成密码“jpc”。编码规律:将字母a变成字母f,即变成其后的第四个字母,x变成b,y变成c,z变成d。
提示:用赋初值的方法是c1,c2,c3的值分别为'f', '1'. 'y',按编码规则改变为c1, c2 ,c3,将结果输出 展开
提示:用赋初值的方法是c1,c2,c3的值分别为'f', '1'. 'y',按编码规则改变为c1, c2 ,c3,将结果输出 展开
1个回答
展开全部
按照你要求随便写了一个:
————————————————————————————————
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
char encryption(char m_str)
{
m_str = (int)m_str + 4;
if ((int)m_str > 122)
{
m_str = (int)m_str - 26;
}
return m_str;
}
int main(int argc, char *argv[])
{
char c1 = 'f';
char c2 = 'l';
char c3 = 'y';
cout << "old string:" << c1 << c2 << c3 << endl;
c1 = encryption(c1);
c2 = encryption(c2);
c3 = encryption(c3);
cout << "new string:" << c1 << c2 << c3 << endl;
return 0;
}
—————————————————————————————————————————
以下方法可以输入任意的小写字母,输出
—————————————————————————————————————————
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
vector<char> m_str;
char s;
while ((s = getchar()) != '\n')
{
m_str.push_back(s);
}
int str_len = m_str.size();
cout << str_len <<endl;
for (int i = 0; i < str_len; i++)
{
m_str[i] = (int)m_str[i] + 4;
if ((int)m_str[i] > 122)
{
m_str[i] = (int)m_str[i] - 26;
}
cout << m_str[i];
}
cout << endl;
return 0;
}
————————————————————————————————
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
char encryption(char m_str)
{
m_str = (int)m_str + 4;
if ((int)m_str > 122)
{
m_str = (int)m_str - 26;
}
return m_str;
}
int main(int argc, char *argv[])
{
char c1 = 'f';
char c2 = 'l';
char c3 = 'y';
cout << "old string:" << c1 << c2 << c3 << endl;
c1 = encryption(c1);
c2 = encryption(c2);
c3 = encryption(c3);
cout << "new string:" << c1 << c2 << c3 << endl;
return 0;
}
—————————————————————————————————————————
以下方法可以输入任意的小写字母,输出
—————————————————————————————————————————
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
vector<char> m_str;
char s;
while ((s = getchar()) != '\n')
{
m_str.push_back(s);
}
int str_len = m_str.size();
cout << str_len <<endl;
for (int i = 0; i < str_len; i++)
{
m_str[i] = (int)m_str[i] + 4;
if ((int)m_str[i] > 122)
{
m_str[i] = (int)m_str[i] - 26;
}
cout << m_str[i];
}
cout << endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询