Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  mm
Language: C/C++
Code:
#include<iostream>
#include<string>
using namespace std;

int main() {
    int n, in;
    string word;
    cin >> n;
    string arr[n]; 
    string helper;
    for (int i = 0; i < n; i++) {
        int count = 1;
        cin >> in;
        cin >> word;
        switch(in) {
            case 1:
                for (int j = 0; j < word.length(); j++) {
                    if (word[j] == word [j + 1]) {
                        count++;
                        continue;
                    }

                    arr[i] += word[j];
                    if (count != 1) {
                     arr[i] +=to_string (count);
                        }
                    count = 1;
                }
                cout << "\n";
                break;
            case 2:
                for (int j = 0; j < word.length(); j++) {
                    int num = 0;
                    if (word[j + 1] >= 48 && word[j + 1] <= 57) {
                        num = word[j + 1] - 48;

                        for (int k = 0; k < num; k++) {
                            arr[i] += word[j];
                        }
                      
                    } else if (!(word[j] >= 48 && word[j] <= 57)) {
                        arr[i] += word[j];
                    }
                    
                }
                    cout << "\n";
                
                break;
        }
    }
    

    for (int p = 0; p < n; p++) {
        cout << arr[p] << endl;
    }
    


    return 0;
}

     
Comments: