【问题标题】:Convert String to Uppercase Decussate in C++在 C++ 中将字符串转换为大写Decussate
【发布时间】:2015-06-23 19:02:24
【问题描述】:

我有这个代码:

        Str UpperCase()
    {
        Str Result;
        int i = 0;
        for (; string[i]; i++)
        {
            if (string[i] <= 'z' && string[i] >= 'a')
            {
                string[i] -= 32;
            }
            Result.string[i] = string[i];
        }
        Result.string[i] = 0;
        return Result;
    }

它将使字符串大写。 如果我希望它是 Decussate,我该怎么办? 示例:嗨,我的名字是 pooya ==> 你好,我的名字是 PoOyA

对不起我的英语不好 谢谢;)

【问题讨论】:

  • 获取输入的大小,并有一个标志来判断字符是偶数还是奇数,并相应地使每个字符的字母大写/小写
  • “如果我想让它成为 Decussate,我应该怎么做?” - 跳到公共汽车前面,让每个人都不必阅读它。
  • 我认为这可能是一个代码战问题。我已经在 J​​ava 中看到了关于 SO 的答案,但我找不到。

标签: c++ uppercase


【解决方案1】:
 Str UpperCase()
    {
        Str Result;
        int i = 0;
        int decussate = 0;
        for (; string[i]; i++)
        {
            if (string[i] <= 'z' && string[i] >= 'a')
            {
                decussate++;
                if( decussate%2 == 1 ){
                    string[i] -= 32;
                }
            }
            Result.string[i] = string[i];
        }
        Result.string[i] = 0;
        return Result;
    }

添加int decussate,通过在每次找到小写字母时将其在奇数和偶数之间更改,它将创建一个模式,其中 1,3,5,7 等字母将大写,假设字符串是小写的。

【讨论】:

    猜你喜欢
    • 2016-01-10
    • 2010-10-18
    • 2021-06-11
    • 2012-01-08
    • 2013-08-02
    • 2014-06-18
    • 1970-01-01
    • 2018-09-16
    相关资源
    最近更新 更多