0
work with strings
From two eight-letter words to form a sequence of letters in which the letters of the first and second words should alternate
7 Respostas
0
If you are working with C++ strings, you should include <string> instead of <string.h>, because <string.h> contains the old C methods that operate on raw pointers.
Also, you don't need an array of strings to hold the merged one, a single one is sufficient.
https://code.sololearn.com/cPtZJTONvsfm/?ref=app
+ 1
Because the loop index advances by 2 it skips letters. Also, slovo1[i+1] causes it to skip slovo1[0] and at the end to read slovo1[8], which is past the end of the string. Is that what you intended? From the problem description I think the output should be "rararararararara" instead of "rararar".
0
Hey Дима Надеин, please specify what exactly your question is. Do you need help with creating such a program? In that case, please provide a code with what you have attempted to solve it by yourself, so we can point out any errors.
0
Hello, I can’t write the program itself. I don’t know how to work with strings
0
Since strings are char arrays, you can easily iterate them with a for-loop. Just set up a new string that can hold the necessary amount of characters, and then fill it by iterating over the strings and copying the characters alternately.
0
I'm trying to do so
#include <iostream>
#include<string.h>
using namespace std;
int main() {
string slovo1={rrrrrrrr};
string slovo2={aaaaaaaa};
string slovo[8];
int i;
for(int i=0;i<8;i=i+2)
slovo=slovo+slovo1[i]+slovo2[i+1];
cout <<endl<<slovo;
return 0;
}
0
shadow thanks for explaining, you are my hero