fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string word;
  7.  
  8. for(int i = 0; i < 2; ++i) {
  9. //cout << "Enter string: ";
  10. if (cin >> word) {
  11. cout << word << " = ";
  12. string::size_type length = word.length();
  13. if ((length % 2) == 1) {
  14. cout << word.substr(length / 2, 1) << endl;
  15. } else {
  16. cout << word.substr((length / 2) - 1, 2) << endl;
  17. }
  18. }
  19. }
  20. }
Success #stdin #stdout 0s 4888KB
stdin
hello middle
stdout
hello = l
middle = dd