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.
#include<bits/stdc++.h>usingnamespacestd;stringltrim(conststring&);stringrtrim(conststring&);/* * Complete the 'strangeCounter' function below. * * The function is expected to return a LONG_INTEGER. * The function accepts LONG_INTEGER t as parameter. */longstrangeCounter(longt){if(t==1){return3;}elseif(t==2){return2;}elseif(t==3){return1;}else{longit=3,i=6;while(it<t){it=it+i;i=i*2;}longdiff=it-t;returndiff+1;}}intmain(){ofstreamfout(getenv("OUTPUT_PATH"));stringt_temp;getline(cin,t_temp);longt=stol(ltrim(rtrim(t_temp)));longresult=strangeCounter(t);fout<<result<<"\n";fout.close();return0;}stringltrim(conststring&str){strings(str);s.erase(s.begin(),find_if(s.begin(),s.end(),not1(ptr_fun<int,int>(isspace))));returns;}stringrtrim(conststring&str){strings(str);s.erase(find_if(s.rbegin(),s.rend(),not1(ptr_fun<int,int>(isspace))).base(),s.end());returns;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Strange Counter
You are viewing a single comment's thread. Return to all comments →