Biến đổi ký tự hoa, ký tự thường trên xâu


Submit solution

Points: 2
Time limit: 1.0s
Memory limit: 977M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, C, C++, C11, CLANG, CLANGX, Classical, COBOL, Coffee, CSC, D lang, DART, F95, FORTH, Fortrn, GAS32, GO, Haskell, Itercal, Java, kotlin, LEAN, LISP, LUA, MONOVB, Nasm, OCAML, Pascal, Perl, php, PIKE, prolog, Pypy, Python, Ruby 2, RUST, Scala, SCM, SED, SWIFT, TCL, TUR, V8JS, VB, ZIG

Bạn hãy lập trình nhập vào một xâu ký tự và thực hiện các công việc sau:

Input

Cho xâu ký tự chỉ gồm các chữ hoa và các chữ thường Tiếng Anh có độ dài không quá 1000 ký tự

Output

Dòng thứ 1 chứa xâu đọc được

Dòng thứ 2 xuất ra xâu mà các chữ hoa thì biến thành chữ thường, và các chữ thường thì biến thành chữ hoa

Dòng thứ 3 xuất ra xâu toàn chữ hoa

Dòng thứ 4 xuất ra xâu toàn chữ thường

Dòng thứ 5 xuất ra những nguyên âm gồm {a,e,i,o,u} và {A,E,I,O,U} thì chữ thường những chữ còn lại thì chữ hoa

Dòng thứ 6 xuất ra bắt đầu là chữ hoa rồi đến chữ thường cứ thế xen kẽ nhau

Ví dụ

Input

DaiHocGiaoThongVanTai

Output

DaiHocGiaoThongVanTai

dAIhOCgIAOtHONGvANtAI

DAIHOCGIAOTHONGVANTAI

daihocgiaothongvantai

DaiHoCGiaoTHoNGVaNTai

DaIhOcGiAoThOnGvAnTaI
tichpx

Comments


  • 0
    Mxeno  commented on May 23, 2025, 1:59 p.m.
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    #define main signed main
    #define elif else if
    #define fix_(x) setprecision(x)<<fixed
    #define TIME (1.0*clock())/CLOCKS_PER_SEC
    void solve(){
        string s, s1,s2,s3,s4,s5;
        char c;
        int i =1;
        while (cin>>c){
            s.push_back(c);
            if (isupper(c)){
                s1.push_back(tolower(c));
            }
            else{
                s1.push_back(toupper(c));
            }
            s2.push_back(tolower(c));
            s3.push_back(toupper(c));
            char tmp = toupper(c);
            if (tmp == 'A' || tmp == 'E' || tmp == 'I' || tmp == 'O' || tmp == 'U'){
                s4.push_back(tolower(c));
            }
            else{
                s4.push_back(toupper(c));
            }
            if (i%2==1){
                s5.push_back(toupper(c));
            }else{
                s5.push_back(tolower(c));
            }
            i++;
        }
        cout << s << "\n";
        cout << s1 << "\n";
        cout << s3 << "\n";
        cout << s2 << "\n";
        cout << s4 << "\n";
        cout << s5 << "\n";
    }
    main(){
        cin.tie(0)->sync_with_stdio(0);
        //freopen("input.txt","r",stdin);
        int t=1;
        // cin>>t;
        while (t--){
            solve();
        }
        return 0;
    }
    

    Sử dụng các hàm có sẵn trong C để xử lý


  • -1
    NguyenDongThinh_CNTT4_K61  commented on Jan. 1, 2022, 4:13 p.m.

    //Các số 65,90,97,122 lần lượt là mã ASCII của các kí tự 'A','Z','a','z' cho ai chưa biết ạ //Code

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        string s;
        cin>>s;
        cout<<s;
        cout<<endl;
        for(int i=0;i<s.length();i++)
        {
            if(int(s[i])>=65&&int(s[i])<=90)
                cout<<(char)(s[i]+32);
            else
                cout<<(char)(s[i]-32);
        }
        cout<<endl;
        for(int i=0;i<s.length();i++)
        {
            if(int(s[i])>=97&&int(s[i])<=122)
                cout<<(char)(s[i]-32);
            else
                cout<<s[i];
        }
        cout<<endl;
        for(int i=0;i<s.length();i++)
        {
            if(int(s[i])>=65&&int(s[i])<=90)
                cout<<(char)(s[i]+32);
            else
                cout<<s[i];
        }
        cout<<endl;
        string c=s;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]>=97&&s[i]<=122)
                c[i] = s[i]-32;
            if(c[i]=='A'||c[i]=='E'||c[i]=='I'||c[i]=='O'||c[i]=='U')
                c[i] = c[i]+32;
        }
        for(int i=0;i<s.length();i++)
            cout<<c[i];
        cout<<endl;
        for(int i=0;i<s.length();i++)
        {
            if(i%2==1)
            {
                if(int(s[i])>=65&&int(s[i])<=90)
                    cout<<(char)(s[i]+32);
                else
                    cout<<s[i];
            }
            if(i%2==0)
            {
                if(int(s[i])>=97&&int(s[i])<=122)
                    cout<<(char)(s[i]-32);
                else
                    cout<<s[i];
            }
        }
    }