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.
I'm having the same problem, did you solve it? What's stranger is that the first testcase doesn't mind whether or not I add a trailing space at the end, but the second two don't work even when they're identical (no trailing whitespace).
intmain(){strings;cin>>s;// Remove spaces from stringfor(autoit=s.begin();it!=s.end();){if(*it==' ')s.erase(it);else++it;}// Caculate grid sizesintfloor=sqrt(s.size());intceiling=sqrt(s.size())+1;if(floor*ceiling<s.size())(floor<ceiling)?floor+=1:ceiling+=1;// Create gridvector<string>encrypted(ceiling);for(inti=0;i<floor;++i){for(intj=0;j<ceiling;++j){encrypted[j]+=s[j+i*ceiling];}}// Ugly output method to remove trailing spacesfor(inti=0;i<encrypted.size();++i){std::cout<<encrypted[i];if(i<encrypted.size()-1)std::cout<<" ";}std::cout<<std::endl;return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
I'm having the same problem, did you solve it? What's stranger is that the first testcase doesn't mind whether or not I add a trailing space at the end, but the second two don't work even when they're identical (no trailing whitespace).