We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 6: Let's Review
Day 6: Let's Review
+ 0 comments my c++ solution, sorry if its a mess
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int test_case; // number of test cases cin >> test_case; for(int i = 0; i < test_case; i++){ string S; cin >> S; // input the strings string even = "", odd = ""; // storage of seperation for (int j = 0; j < S.length(); j++){ if (j % 2 == 0){ even += S[j]; // to append } else { odd += S[j]; } } cout << even << " " << odd << endl; } return 0; }
+ 0 comments This solution works on PyCharm, but when I submit the code, it is rejected. Why??
def print_even_odd_characters(s):
even_characters = [] odd_characters = [] for i in range(len(s)): if i % 2 == 0: even_characters.append(s[i]) else: odd_characters.append(s[i])
print("".join(even_characters), "".join(odd_characters))
if name == "main": s = input() print_even_odd_characters(s)
+ 0 comments Simple C++ Solution :)
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; void seprateString(string S){ for(int i=0;i<S.length();i++){ if(i%2 == 0){ cout<<S[i]; } } cout<<" "; for(int j=0;j<S.length();j++){ if(j%2 != 0){ cout<<S[j]; } } cout<<endl; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int T; cin>>T; for(int i = 0;i<T;i++) { string S; cin>>S; seprateString(S); } return 0; }
+ 1 comment n=int(input()) for i in range(n): x=input() print(f"{x[0::2]} {x[1::2]}")
Very simplest and efficient method to solve this question in Python
[deleted] + 0 comments Python 3 Solution
n = int(input()) for i in range(0, n): line = input() print(line[::2], line[1::2], sep=" ")
Load more conversations
Sort 3242 Discussions, By:
Please Login in order to post a comment