28 条题解

  • 1
    @ 2023-4-17 21:06:17
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        string a;
        cin >> a;
        for (int i = 0;i < a.length();i++)
        {
            if (a[i] >= 'a' && a[i] <= 'z')
            {
                a[i] -= 32;
            }
            else if(a[i] >= 'A' && a[i] <= 'Z')
            {
                a[i] += 32;
            }
            else
            {
                continue;
            }
        }
        cout << a;
        return 0;
    }
    

    这题主要用string变量+‘阿斯克’编码表判断 一如坤往的简单

    • 1
      @ 2022-11-14 13:15:44

      本题主要考察sting和ASCII表

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

      • 1
        @ 2022-8-26 19:39:46

        这题真的超——级简单!

        一个for循环就搞定啦~

        主要就是要记住大小写的转换方法——

        大写转小写:+=32

        小写转大写:-=32

        上代码

        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            string s;
            cin >> s;
            if (s.length()<= 80){
                for(int i = 0; i < s.length(); i++){
                    if (s[i] >='a' && s[i] <='z'){
                        s[i] -= 32;
                    }else if (s[i] >='A' && s[i] <='Z'){
                        s[i] += 32;
                    }
                }
                cout << s;
            }
            return 0;
        }
        

        (已AC,放心看~)

        记得点赞谢谢

        • @ 2022-9-12 13:56:05

          UP,麻烦解释一下小写转大写and大写转小写是啥子原理啊

          ASCII码啊

        • @ 2023-8-5 20:08:28

          常用字词表里面大写和小写同样的字母相差32。比如大写a的编号是65,小写a的编号是97,之间相差32。@

      • 0
        @ 2024-4-6 20:12:02

        其实不用getline也可以

        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            string a;
            cin>>a;
            for(int i=0;i<a.length();i++)
            {
                if(a[i]>='a' && a[i]<='z')
                {
                    a[i]-=32;
                }
                else if(a[i]>='A' && a[i]<='Z')
                {
                    a[i]+=32;
                }
            }
            cout<<a;
        }
        
        • 0
          @ 2023-11-25 11:54:59
          #include <bits/stdc++.h>
          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]+=32;
                  }
                  else if (s[i] >= 'a' && s[i] <= 'z'){
                      s[i]-=32;
                  }
              }
              cout << s;
              return 0;
          }
          
          • 0
            @ 2022-8-21 22:23:10
            for (int i = 0; i < n.length(); i++)
                {
                    if (n[i]>='a' && n[i]<='z') 
                    {
                        n[i]=n[i]-32;
                    }
                    else if (n[i]>='A' && n[i]<='Z') 
                    {
                        n[i]=n[i]+32;
                    }
                    
                }
            
            • -1
              @ 2022-4-28 20:52:08

              上课学过这个题,for循环遍历字符串,里面嵌套if-else if即可。

              • -13
                @ 2022-7-26 20:20:31

              信息

              ID
              182
              时间
              1000ms
              内存
              16MiB
              难度
              5
              标签
              递交数
              3646
              已通过
              1314
              上传者