ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1226. esreveR redrO

What wrond with my solution - Please Help
Posted by VladG 6 Nov 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;
  }
}