ACM模版

描述

题解

其实很简单的一道题,但是牛客网的测评系统有问题。给了两种代码,不知道第一种算不算违规,因为是直接遍历两边,先输出小写,再输出大写;第二种就是利用许多次交换实现真正的字符转移,由于不能申请额外的空间,所以没有使用第三方变量的方法交换数据,而是使用异或的方法搞搞。

代码

One:

//#include <iostream>
//#include <string>
//
//using namespace std;
//
//int main(int argc, const char * argv[])
//{
   
// string s;
// cin >> s;
// 
// for (int i = 0; i < s.length(); i++)
// {
   
// if (s[i] >= 'a' && s[i] <= 'z')
// {
   
// cout << s[i];
// }
// }
// for (int i = 0; i < s.length(); i++)
// {
   
// if (s[i] >= 'A' && s[i] <= 'Z')
// {
   
// cout << s[i];
// }
// }
// cout << '\n';
// 
// return 0;
//}

Two:

#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char * argv[])
{
    string s;
    cin >> s;

    for (int i = (int)s.length() - 1; i >= 0; i--)
    {
        if (s[i] >= 'A' && s[i] <= 'Z')
        {
            for (int j = i; j < s.length(); j++)
            {
                if (s[j + 1] >= 'a' && s[j + 1] <= 'z')
                {
                    s[j] ^= s[j + 1];
                    s[j + 1] ^= s[j];
                    s[j] ^= s[j + 1];
                }
            }
        }
    }
    cout << s << '\n';

    return 0;
}