+ 2

Can you solve this :- Expand alphabets

Given a string S with alphabets and their count, repeat the alphabets based on their count and print the value as the output. Input Format: The first line contains S. Output Format: The first line contains the alphabets repeated based on their count. Boundary Condition: 1 <= Length of S <= 100 Example Input/Output 1: Input: a2c5z4 Output: aaccccczzzz input: a10b10c10 output: aaaaaaaaaabbbbbbbbbbcccccccccc input: a4b5c2f7g3 output: aaaabbbbbccfffffffggg

26th Feb 2018, 7:02 AM
Samar
Samar - avatar
9 Réponses
26th Feb 2018, 3:35 PM
John Wells
John Wells - avatar
+ 3
got the easiest way in c++ #include <iostream> using namespace std; int main(int argc, char** argv) {int i,j; char a; while(cin>>a>>i) for(j=0;j<i;j++) cout<<a; }
27th Feb 2018, 6:10 AM
Samar
Samar - avatar
+ 1
a=input().rstrip() c=[] d=[] for i in range(len(a)): if(i%2==0): c.append(a[i]) else: d.append(int(a[i])) k=0 for i in c: for j in range(d[k]): print(i,end=' ') k=k+1 //Follow answers from https://vitcrack.blogspot.com
26th Feb 2018, 9:19 AM
komalvg
0
maxcookmax , read the examples once again what to do if input is a12b20c29 because here input[0]=a but the number after 'a' is 12 ,if you give input[1] then you will get only 1 not 12
26th Feb 2018, 7:06 AM
Samar
Samar - avatar
0
komal, what will you do if input is a16c10f13 (see the examples )
26th Feb 2018, 12:23 PM
Samar
Samar - avatar
0
Thank you Mr.John Wells ,It was a fantastic answer,Can you do that once again for me in c++ or in python on in java .Because I don't know kotlin.
26th Feb 2018, 5:47 PM
Samar
Samar - avatar