2025年西南石油大学计算机考研复试机试真题
2025年西南石油大学计算机考研复试上机真题
历年西南石油大学计算机考研复试上机真题
历年西南石油大学计算机考研复试机试真题
更多学校题目开源地址:https://gitcode.com/verticallimit1/noobdream
N 诺 DreamJudge 题库:输入 “学校名称” 即可筛选该校历年机试真题,题目均在考纲范围内,按难度自动排序。还可搭配《计算机考研机试攻略》刷题,书中题目可通过题号直接在题库中查找。
加密算法
题目描述
Time Limit: 1000 ms
Memory Limit: 256 mb
编写加密程序,加密规则为:将所有字母转化为该字母后的第三个字母,即A->D、B->E、C->F、......、Y->B、Z->C。小写字母同上,其他字符不做转化。输入任意字符串,输出加密后的结果。
例如:输入"I love 007",输出"L oryh 007"
输入输出格式
输入描述:
输入一行字符串,长度小于100。
输出描述:
输出加密之后的结果。
输入输出样例
输入样例#:
I love 007
输出样例#:
L oryh 007
代码一
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- char c[105];
- gets(c);
- int len = strlen(c);
- for(int i=0;i<len;i++){
- if(c[i]>='A'&&c[i]<='Z'){
- c[i]+=3;
- if(c[i]>'Z'){
- c[i]-=26;
- }
- }
- else if(c[i]>='a'&&c[i]<='z'){
- c[i]+=3;
- if(c[i]>'z'){
- c[i]-=26;
- }
- }
- else{
- continue;
- }
- }
- puts(c);
- return 0;
- }
代码二
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- string s ;
- getline(cin,s);
- for(int i=0;i<s.size();i++){
- if(s[i]<='z'&&s[i]>='a'){
- s[i] = 'a' + (s[i]-'a'+3)%26;
- }
- if(s[i]<='Z'&&s[i]>='A'){
- s[i] = 'A' + (s[i]-'A'+3)%26;
- }
- }
- cout<<s;
- return 0;
- }
代码三
- #include<stdio.h>
- #include<string.h>
- int main(){
- char s[105];
- gets(s);
- int len = strlen(s);
- for(int i=0; i<len; i++){
- // 处理小写字母
- if(s[i] >= 'a' && s[i] <= 'z'){
- s[i] += 3;
- // 偏移后超过z,循环到开头(z+3=122+3=125 → 125-26=99=c)
- if(s[i] > 'z'){
- s[i] -= 26;
- }
- }
- // 处理大写字母(单独判断,避免和小写混淆)
- else if(s[i] >= 'A' && s[i] <= 'Z'){
- s[i] += 3;
- // 偏移后超过Z,循环到开头
- if(s[i] > 'Z'){
- s[i] -= 26;
- }
- }
- // 非字母字符:不处理
- }
- printf("%s\n", s);
- return 0;
- }