fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. bool MakeHoge(std::string Str){
  5. int SP = 0;
  6. for (std::size_t i = 0; i+SP < Str.size(); i++){
  7. if (Str[i + SP] == ' ')SP++;
  8. if ((i) % 2 == 0)std::cout << Str[i + SP] << ' ';
  9. }
  10. std::cout << std::endl;
  11. std::cout << ' ';
  12. SP = 0;
  13. for (std::size_t i = 0; i+SP < Str.size(); i++){
  14. if (Str[i + SP] == ' ')SP++;
  15. if ((i) % 2 == 1)std::cout << Str[i + SP] << ' ';
  16. }
  17. std::cout << std::endl;
  18. return true;
  19. }
  20.  
  21. int main(){
  22. std::string Str1= "123456789";
  23. std::string Str2 = "The earth turns around the sun.";
  24. std::string Str3 = "wa wa wa w w .";
  25.  
  26. MakeHoge(Str1);
  27. MakeHoge(Str2);
  28. MakeHoge(Str3);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1 3 5 7 9 
 2 4 6 8 
T e a t t r s r u d h s n 
 h e r h u n a o n t e u . 
w w w w . 
 a a a w