Problem C: 字符串译码(字符数组或字符串)

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:30 Solved:12

Description

编写一个译码程序,将输入的一串字符(只有小写字母、数字和空格,输入时以句号结束)翻译成原码。译码规则如下:
①数字0,1,2,3,…,9分别和字母a,b,c,…,j互换
②字母k,m,p,t,y分别和它们的后继(l,n,q,u,z)互换
③其他字母和空格保持不变。

Input

输入一个字符串(含有的字符个数不多于100个)

Output

输出字符串原码

Sample Input Copy

how are you 1536 next year.

Sample Output Copy

7ow 0r4 zot bfdg m4xu z40r.

HINT

英文句子中单词与单词之间用空格隔开,不考虑其它情况。
C++:
使用cin语句输入字符串时,遇到空格就结束,也就是说只能输入一个单词,而不能输入整行或包含空格的字符串。
当把字符串直接定义为string型时,可以用getline()函数来读取字符串,如"getline(cin,str);",其中cin指的是输入流,str是从输入流中读入的字符串存放的变量。
示例:
如输入内容是hello world
(1)

#include<bits/stdc++.h> //包含万能头文件 
using namespace std; //使用标准命名空间 
int main() //主函数,返回值的数据类型是整型 
{
string str; //定义1个字符串变量str 
cin>>str; //使用cin语句输入字符串时,遇到空格就结束,str的内容是hello

return 0;
}

(2)
#include<bits/stdc++.h> //包含万能头文件 
using namespace std; //使用标准命名空间 
int main() //主函数,返回值的数据类型是整型 
{
string str; //定义1个字符串变量str 
int i;
getline(cin,str); //读入1个字符串,getline接受一个字符串,可以接收空格并输出,str内容是hello world
return 0;

}

字符串视频讲解:https://www.bilibili.com/video/BV1CWCYYmEvj/?spm_id_from=333.788.videopod.sections&vd_source=ed609f9463861996afb742d2bd8b5a46

1.length()成员函数

length()函数是string的内置成员函数,用于返回string类型字符串的实际长度。
示例1:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s="hello world!";
  cout<<s.length()<<endl;
  return0;
}
输出:12

2.size()成员函数

size()函数与length()一样,没有本质区别。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s= "hello world!";
    cout << s.size() << endl;
    return 0;
}

输出结果:12


Source/Category