2808: Correct the wrong question.

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 301  Solved: 161
[ Submit ][ Status ][ Web Board ]

Description

The following program converts uppercase letters into lowercase letters and lowercase letters into uppercase letters in a string (the length of the string does not exceed 10). The program segment marked with * is wrong, and the program statement cannot be added or subtracted when the error is corrected. Submit this part of the statement.

Input

Enter a string of characters, including upper and lower case letters, and other legal characters.

Output

Output a string of characters, converting uppercase letters to lowercase and lowercase letters to uppercase.

Sample Input

AB2cd

Sample Output

ab2CD

HINT

#include<iostream>

#include<string.h>

using namespace std;

intmain()

{

       char a[10];int n;

       cin>>a;

n=strlen(a);

****************Wrong part ************

for(int i=0;i<=n;i++)

        {if(a[i]>='A'&&a[i]<='Z')a[i]=a[i]+32;

          if(a[i]>='a'&&a[i]<='z')a[i]=a[i]-32;}

    **********************************

       cout<<a;

       return 0;

}

Source

tanzheng

Code:

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char a[10];int n;
    cin>>a;
n=strlen(a);
for(int i=0;i<n;i++)
    {
if(a[i]>='A'&&a[i]<='Z')
a[i]=a[i]+32;
    else if(a[i]>='a'&&a[i]<='z')
a[i]=a[i]-32;
}
    cout<<a;
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325846897&siteId=291194637