You are given a string which consist of characters and numbers of unknown length. It is in the following form: "nXnXnX....", where n equals a number and X a letter. (The 1st nX doesn't equal to the 2nd nX, for example nXnX could equal to 2A4B). Then, you have to output the string which is produced when you output n times the X character.
Example Input:
3A3F4R6A
Example Output:
AAAFFFRRRRAAAAAA
I came up with the following algorithm, but it was an epic fail, of course, because when a number is being input to a string it converts to a character, so if you try to make it an integer again you just get its ASCII value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <algorithm>
usingnamespace std;
int main(){
string word;
cin>>word;
for (int i=0; i<word.size(); i=i+2){
for (int j=0; j<word[i]; j++){
cout<<word[i+1];
}
}
}
Even though I know it's correct since I ran it in my offline compiler, hacerrank's autocompile engine says the outputs are wrong. It's a problem with the online compiler, so is there any way to do this with another way?
I've no idea what the linked page was supposed to be - I get a big 404 not found.
If you show your latest code then there might be something that could be adjusted.
As for "is there any way to do this with another way?" - well of course. There are always thousands of ways to tackle a problem. I merely suggested one which came readily to mind.