Question d’entretien chez Meta

Revert the given string and return the resulting string. Ex: input: "face" , result: "ecaf"

Réponses aux questions d'entretien

Utilisateur anonyme

7 juil. 2015

#include #include using namespace std; void revStr(string& str) { std::cout << str << endl; char* ep = &(str[str.size() - 1]); char* bp = &str[0]; for( ; ep != bp ; ep--, bp++) { char c = *ep; *ep = *bp; *bp = c; } } int main() { string str = "semih.kekul"; revStr(str); cout << str << endl; }

Utilisateur anonyme

5 sept. 2012

Just create another string array and copy the contents of the given array to new array backwards , dont forget to get space for N+1 , not just for N, since there is null char at the end of the string and dont forget to put it.