美文网首页
【MAC 上学习 C++】Day 48-1. 实验7-3-4 字

【MAC 上学习 C++】Day 48-1. 实验7-3-4 字

作者: RaRasa | 来源:发表于2019-10-11 19:43 被阅读0次

实验7-3-4 字符串替换 (15 分)

1. 题目摘自

https://pintia.cn/problem-sets/13/problems/525

2. 题目内容

本题要求编写程序,将给定字符串中的大写英文字母按以下对应规则替换:

对应字母 原字母
Z A
Y B
X C
W D
C X
B Y
A Z
输入格式:

输入在一行中给出一个不超过80个字符、并以回车结束的字符串。

输出格式:

输出在一行中给出替换完成后的字符串。

输入样例:

Only the 11 CAPItaL LeTtERS are replaced.

输出样例:;

Lnly the 11 XZKRtaO OeGtVIH are replaced.

3. 源码参考
#include <iostream>

using namespace std;

#define len 80

int main()
{
  char c[80], m;
  int i, n;
  int cnt;

  cin.get(c, len, '\n');
  n = strlen(c);

  cnt = 0;
  for(i = 0; i < n; i++)
  {
    m = c[i];
    if((m >= 'A') && (m <= 'Z'))
    {
      m = 'Z' - m + 'A';
    }

    c[i] = m;
  }

  for(i = 0; i < n; i++)
  {
    cout << c[i];
  }

  cout << endl;

  return 0;
}

相关文章

网友评论

      本文标题:【MAC 上学习 C++】Day 48-1. 实验7-3-4 字

      本文链接:https://www.haomeiwen.com/subject/yfsgectx.html