3 solutions

  • 6
    @ 2024-7-25 16:16:22

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int k;
        cin>>k;
        for(int i=1;i<=k;i++)
        {
            string s1;
            cin>>s1;
            int n=s1.size();
            for(int j=0;j<n;j+=2)
            {
                swap(s1[j],s1[j+1]);
            }
            cout<<s1<<endl;
        }
        return 0;
    }
    • 0
      @ 2026-4-1 10:49:17

      #include <bits/stdc++.h> using namespace std; int main() { int k; cin>>k; for(int i=1;i<=k;i++) { string s1; cin>>s1; int n=s1.size(); for(int j=0;j<n;j+=2) { swap(s1[j],s1[j+1]); } cout<<s1<<endl; } return 0; }

      • -4
        @ 2024-7-24 16:17:45
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
             int t;
             cin>>t;
             while(t--){
                  string s;
                  cin>>s;
                  if(s.size()==1){
                       cout<<s<<endl;
                  }
                  else{
                       for(int i=0,j=1;i<s.size(),j<s.size();i+=2,j+=2){
                            swap(s[i],s[j]);
                       }
                       cout<<s<<endl;
                  }
                  
             }
             return 0;
        }
        
        • 1

        Information

        ID
        91
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        1
        Tags
        (None)
        # Submissions
        58
        Accepted
        35
        Uploaded By