0
Help. I submitted a homework to a page and it gave 0/20
You are given two strings. You need to merge them intermittently as shown below. Input acdefghijkl xyza23 Output axcydzeaf2g3hijkl The example i submitted:
13 Respostas
+ 1
You can accomplish this with just one loop instead. Use the iterator variable in the loop to keep track of the position between the two arrays, and that's how you'll access the stored value for each during each iteration of the loop. Then inside of the loop, have it assign the current value from the first array to your result array, and then the value from the second array to your result array. When it's done looping, it'll have generated the string you're seeking.
Btw, the code you posted appears to be perfectly fine. So I'm not sure what your issue is. It's not how I would, or recommend, going about resolving it, but it should still work as expected.
+ 1
Okay. This what you're trying to do?
https://code.sololearn.com/cM3Z6jaS7w16/#cpp
#include<iostream>
#include <strings.h>
using namespace std;
int main() {
int maxIterations = 0;
char st1 [] = "abcdefgh";
char st2 [] = "tuvwxyz";
string res = "";
if(strlen(st1) > strlen(st2))
maxIterations = strlen(st1);
else
maxIterations = strlen(st2);
for(int i = 0; i < maxIterations; ++i){
res.push_back(st1[i]);
res.push_back(st2[i]);
}
cout << res << endl;
return 0;
}
:::: OUTPUT :::::
atbucvdwexfygzh
+ 1
Regi can I see the site?
+ 1
It is a site created by our teacher.He post them in piazza
+ 1
Regi okay, now for your code, I can make it and show you my way in C.
if you'd like to .
0
#include <stdio.h>
#include <strings.h>
int main() {
char st1 [] = "abcdefgh";
char st2 [] = "tuvwxyz";
char res[30];
int x,y;
for(y = 0,x = 1; x < 30, y < strlen(st2); x+= 2, y++){
res[x] = st2[y];
}
for(y = 0,x = 0; x < 30, y < strlen(st1); x+= 2, y++){
res[x] = st1[y];
}
printf(" %s", res);
return 0;
}
0
I need to do it with strings
0
You could replace char [] with string. Strings support using [] to access single characters
0
Regi this is almost not C++. you shouldn't code like that in C++, it's more C style.
C++ is object oriented, which means you have classes and objects.
replace strings.h with string. to using string object from C++98.
strlen shouldn't be used, you can use str.length(), and you can access the chars array, by using the bracket [].
0
The site that i subimt my execrsices didn't accept it.How should i write it?
0
Regi this is weird, are you sure the site support C++ and not C?
0
Yes because you can change the programming languages.It gave me 0/20 points
0
Will that help me because i need it in c++