Created
November 20, 2024 08:44
-
-
Save ProfAndreaPollini/85add17ad46b3586a72394e8349e70c2 to your computer and use it in GitHub Desktop.
Esercizio C++ sulle stringhe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inserrita una stringa,, stamparla dopo aver scambiato i caratteri | |
#include <iostream> | |
#include <string> | |
int main() { | |
std::string in_word; | |
//std::string out_word; | |
char c; | |
int exchanges = 0; | |
std::cout << "Inserisci stringa: "; | |
std::getline(std::cin,in_word); | |
exchanges = in_word.length()/2; | |
std::cout << "hai inserito: " << in_word << "\n"; | |
for (int i = 0; i < exchanges; ++i) { | |
c = in_word[i]; | |
in_word[i] = in_word[in_word.length()-1-i]; | |
in_word[in_word.length()-1-i] = c; | |
} | |
std::cout << in_word; | |
// for(int i = in_word.length()-1; i >=0; i--) { | |
// out_word = out_word + in_word[i]; | |
// } | |
// | |
// std::cout << "reversed: " << out_word; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment