|
|
вернуться в форумWhat wrond with my solution - Please Help Послано VladG 6 ноя 2002 12:07 #include <iostream.h> #include <string.h> #include <stdio.h> const int MAX_TEXT_SIZE = 300; enum State {NORMAL, WORD}; bool isSmallLetter(char ch) { if (ch >= 'a' && ch <= 'z') return true; else return false; } bool isBigLetter(char ch) { if (ch >= 'A' && ch <= 'Z') return true; else return false; } bool isLetter(char ch) { if (isSmallLetter(ch) || isBigLetter(ch) || ch == '-') return true; else return false; } void main() { char text[MAX_TEXT_SIZE]; int i, j, firstLetter; State state; while (!cin.eof()) { cin.getline(text, MAX_TEXT_SIZE); state=NORMAL; for (i=0; i<strlen(text); i++) { switch (state) { case NORMAL: if (isLetter(text[i])) { state = WORD; firstLetter = i; } else cout << text[i]; break; case WORD: if (!isLetter(text[i])) { state = NORMAL; for (j=i-1; j>= firstLetter; j--) if (text[j] != '-') cout << text[j]; cout << text[i]; } break; } } if (state == WORD) { for (j=i-1; j>= firstLetter; j--) if (text[j] != '-') cout << text[j]; } cout << endl; } } |
|
|