字符串的反码【简单 / 字符串处理】

字符串的反码【简单 / 字符串处理】_第1张图片
https://www.nowcoder.com/practice/01b7dae14d1b464db5f9259e90d9a35e?tpId=40&tqId=21503&rp=1&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan%2Fquestion-ranking&tab=answerKey

#include
using namespace std;
int main()
{
     
    string s;
    cin >> s;
    for(int i=0; i<s.length(); i++)
    {
     
        if( s[i]>='a'&&s[i]<='z'  )
        {
     
            s[i] = 'z' + 'a' - s[i];
        }
        if( s[i]>='A'&&s[i]<='Z' )
        {
     
            s[i] = 'Z' + 'A' - s[i];
        }
    }
    cout << s << endl;
}
#include
#include
#include
using namespace std;
int main(void)
{
     
	string str;
	cin>>str;
	char s[100];
	for(int i=0;i<str.size();i++)
	{
     
		if(str[i]>='a'&&str[i]<='z')
		{
     
			s[i]='z'-(str[i]-'a');
			continue;
		}
		if(str[i]>='A'&&str[i]<='Z')
		{
     
			s[i]='Z'-(str[i]-'A');
			continue;
		}
		s[i]=str[i];
	}
	s[str.size()]='\0';
	printf("%s\n",s);
	return 0;
}

你可能感兴趣的:(牛客,历年计算机考研复试上机题,字符串,c++)