+ 5

I have a situation with my "The spy life" code coach solution

Reff: You are a secret agent, and you receive an encrypted message that needs to be decoded. The code that is being used flips the message backwards and inserts non-alphabetic characters in the message to make it hard to decipher. Task: Create a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message. Input Format: A string of characters that represent the encoded message. Output Format: A string of character that represent the intended secret message. Sample Input: d89%l++5r19o7W *o=l645le9H Sample Output: Hello World Problem: My code works fine for the test cases, but don't get approved. my code: #include <iostream> ...(in the comments, thanks)

12th Apr 2022, 9:48 AM
MikO
MikO - avatar
15 Antworten
0
Emeka "I made it so to initialize the length of rev, so as to make changes to it "--sry I don't understood it. I about, your rev string length should be less than the original input string. Because you have to remove non-alphabets. Setting a NULL will not remove characters. So you have characters but invisible, I think this is causing the problem. Because it checks output with expected output lexicographically... Instead setting null, add only those which are alphabets to rev by rev+=wrd[s]; will solve the problem easily I think. No inbuilts used also.. Hope it helps..
14th Apr 2022, 8:57 AM
Jayakrishna 🇮🇳
+ 3
#include <iostream> using namespace std; int main() { int a, b, i, j = 0; string wrd, rev; getline(cin, wrd); rev = wrd; for (i = 0; wrd[i] != '\0'; i++) { a = i; } for (b = 0; b < i; b++) { rev[b] = wrd[a]; a--; } for (int s = 0; s < rev.length(); s++) { for (char c = 'a'; c <= 'z'; c++) { if (rev[s] == c) { j = 1; } } if (j != 1) { if (rev[s] == ' ') { rev[s] = ' '; } else { rev[s] = NULL; } } j = 0; } cout << rev; return 0; } what do you think is possibly wrong?
12th Apr 2022, 9:48 AM
MikO
MikO - avatar
+ 3
Jayakrishna🇮🇳 , I made it so to initialize the length of rev, so as to make changes to it
14th Apr 2022, 6:23 AM
MikO
MikO - avatar
+ 3
Emeka You should also check for * symbol and remove code that does nothing
14th Apr 2022, 6:53 AM
Ilyas Bakirov
Ilyas Bakirov - avatar
+ 3
Ilyas Bakirov , I appreciate the fact that you used inbuilt libraries. I believe this is sololearn trying to curb my approach of "writing from scratch"😂. Thanks... though I'm still open to knowing "what's really happening" so: incase of next time Jayakrishna🇮🇳 , thanks.
14th Apr 2022, 8:13 AM
MikO
MikO - avatar
+ 3
Jayakrishna🇮🇳 https://code.sololearn.com/cwra9d4UaP57/?ref=app this was the initial idea, but I didn't want to have to create another variable lol. So I modified existing one instead. thanks 🤝🏼 UPDATE(III)
14th Apr 2022, 9:13 AM
MikO
MikO - avatar
+ 3
Emeka Yes, your code longer and I'm glad you succeeded 👍 As Jayakrishna🇮🇳 said your code duplicates itself for upper case letters and it's OK for the beginning 😜 Coding must go smoothly and with no hard, so try to simplify things and code where you see and can do, by the way built-in functions are not evils 👹
14th Apr 2022, 12:52 PM
Ilyas Bakirov
Ilyas Bakirov - avatar
+ 2
I got two warnings, so I made little changes: https://code.sololearn.com/c5Pz001i3fxn/?ref=app UPDATE(II)
14th Apr 2022, 7:51 AM
MikO
MikO - avatar
+ 2
Syed huzef Ali Your code from different task 🙂
14th Apr 2022, 12:55 PM
Ilyas Bakirov
Ilyas Bakirov - avatar
+ 1
I think, your rev length is same as wrd length.. but it should be less. so you have invisible charectets in rev.. may this is the problem... Emeka instead use, string rev=""; rev+=wrd[s] it can be improved much... try again. hope it helps..
12th Apr 2022, 10:16 AM
Jayakrishna 🇮🇳
+ 1
Emeka What are you achieve with first for loop where you assign a = i? Can you place your code in Code Playground?
14th Apr 2022, 2:39 AM
Ilyas Bakirov
Ilyas Bakirov - avatar
+ 1
Ilyas Bakirov it's actually for a character array case(word reverse), cause we don't know how long the real elements are. I changed it to string and forgot to use .length() instead
14th Apr 2022, 6:14 AM
MikO
MikO - avatar
+ 1
Emeka Except the warnings this should work I think... Is it? And just for info, may be you know it! for (char c = 'a'; c <= 'z'; c++) { if (rev[s] == c) { filtered+=rev[s]; } } Can be rewrite without loop, simply: if( rev[s] >= 'a' && rev[s]<='z') filtered += rev[s]; for capital and space also be included in this single if condition.. You're welcome..
14th Apr 2022, 11:48 AM
Jayakrishna 🇮🇳
- 1
#include <iostream> using namespace std; int main() { int t; cin>>t; while(t--) char x[7]={'!','@','#','
#x27;,'%','&','*'}; int i=7; cin>>i; for(i=1;i<=7;i++){ if("password passes the minimum 2 numbers") cout<<"strong"<<i<<endl; cout<<"hello@$world19"<<endl; } else { cout<<"weak"; } return 0; }
14th Apr 2022, 9:01 AM
Syed huzef Ali