大小写字母替换 正确的程序是什么

编写程序,读入一行字符(长度小于1000),将其中出现的小写字母替换为大写字母并输出。

Microsoft Edge is the only browser optimized for Windows.
MICROSOFT EDGE IS THE ONLY BROWSER OPTIMIZED FOR WINDOWS.

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string line;
    getline(cin, line);
    for_each(line.begin(), line.end(), [](auto &c) { c = toupper(c); });
    cout << line << endl;
    return 0;
}
$ g++ -Wall main.cpp
$ ./a.out
Microsoft Edge is the only browser optimized for Windows.
MICROSOFT EDGE IS THE ONLY BROWSER OPTIMIZED FOR WINDOWS.

你题目的解答代码如下:

#include<stdio.h>
#include<string.h>

int main()
{
    int n,i;
    char s[1001] = {0};
    gets(s);
    int len = strlen(s);
    for (i = 0; i < len; i++)
        if (s[i] >= 'a' && s[i] <= 'z')
            s[i] -= 32;
    printf("%s\n", s);
    return 0;
}

img

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

#include<iostream>
 using namespace std;
int main()
{
    int n,i=0;
    char s[1001] = {0};
    gets(s);
    while(s[i] != '\0')
    {
          if(s[i] >='a' && s[i]<='z')
              s[i] -= 32;
          i++;
    }
    cout<<s<<endl;
    return 0;
}