Where Does It Fit?


TCEA State Programming Contest
April 28, 2001

Problem 2.2 Where Does It Fit?

General Statement: For an input word, determine whether it is alphabetically located before the word EXERCISE, after the word MUSCLES, or between EXERCISE and MUSCLES.

Input: The first line of the data set for this problem is an integer that represents the number of words in the list. Each word is on a separate line

Output: The output is to be formatted exactly like that for the sample output given below.

Assumptions: All letters are upper case.

Sample Input:
4
REST
ACHE
STRETCH
GYM

Sample Output:
REST IS AFTER MUSCLES
ACHE IS BEFORE EXERCISE
STRETCH IS AFTER MUSCLES
GYM IS BETWEEN EXERCISE AND MUSCLES

#include
#include
using namespace std;

int main ()
{
int dataSet;
cin >> dataSet;

while ( dataSet– ) {

string s;
cin >> s;

if ( s > “MUSCLES” )
cout << s << " IS AFTER MUSCLES" << endl; else if ( s < "EXERCISE" ) cout << s << " IS BEFORE EXERCISE" << endl; else cout << s << " IS BETWEEN EXERCISE AND MUSCLES" << endl; } return 0; } [/sourcecode]

Advertisements

5 thoughts on “Where Does It Fit?

  1. as far as i concern, The code is correct. This is not my headache whether this code performs in Visual C++ 6.00 compiler or not. I didn’t make such promise to secure this.
    This code shows 0 errors in MinGW (GNU) compiler [http://www.mingw.org/] and hence runs successfully.
    The reason might be Visual C++ doesn’t support C++ string class library.
    For more info. about C++ Standard Library String Class :
    http://www.cplusplus.com/reference/string/string/
    http://www.cppreference.com/wiki/string/start
    http://www.cprogramming.com/tutorial/string.html

  2. A CORRECT CODE FOR THIS PROBLEM CAN BE SEEN RIGHT BELOW (REMOVE THE SPACES IN THE HEADER FILES BEFORE RUNNING):

    #include
    #include

    int main(){
    char word[100];
    int x,i,j,l;
    printf(“please enter the number of inputs: “);
    scanf(“%d”,&x);
    printf(“\n”);
    fgets(word,100,stdin);
    for(j=1;j<=x;j++){
    printf("please enter a word: ");
    fgets(word,100,stdin);
    for(i=0;i<100;i++){if(word[i]=='\n'){word[i]='\0';}}
    l=strlen(word);
    printf("\n");
    if(strcmp(word,"EXERCISE")==0){printf("you entered EXERCISE.\n");
    printf("\n");}
    if(strcmp(word,"MUSCLES")==0){printf("you entered MUSCLES.\n");
    printf("\n");}
    if(word[0]’E’&&word[0]’M’){printf(“%s comes after MUSCLES\n”,word);
    printf(“\n”);}
    if(word[0]==’E’){
    if(word[1]’X’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[1]==’X’){
    if(word[2]’E’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[2]==’E’){
    if(word[3]’R’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[3]==’R’){
    if(word[4]’C’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[4]==’C’){
    if(word[5]’I’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[5]==’I’){
    if(word[6]’S’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[6]==’S’){
    if(word[7]’E’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[7]==’E’){
    if (word[8]>0){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}}}}}}}}}
    if(word[0]==’M’){
    if(word[1]’U’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[1]==’U’){
    if(word[2]’S’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[2]==’S’){
    if(word[3]’C’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[3]==’C’){
    if(word[4]’L’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[4]==’L’){
    if(word[5]’E’){printf(“%s is comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[5]==’E’){
    if(word[6]’S’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[6]==’S’){
    if (word[7]>0){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}}}}}}}}}
    return 0;}

  3. #include
    #include
    int main(){
    char word[100];
    int x,i,j,l;
    printf(“please enter the number of inputs: “);
    scanf(“%d”,&x);
    printf(“\n”);
    fgets(word,100,stdin);
    for(j=1;j<=x;j++){
    printf("please enter a word: ");
    fgets(word,100,stdin);
    for(i=0;i<100;i++){if(word[i]=='\n'){word[i]='\0';}}
    l=strlen(word);
    printf("\n");
    if(strcmp(word,"EXERCISE")==0){printf("you entered EXERCISE.\n");
    printf("\n");}
    if(strcmp(word,"MUSCLES")==0){printf("you entered MUSCLES.\n");
    printf("\n");}
    if(word[0]’E’&&word[0]’M’){printf(“%s comes after MUSCLES\n”,word);
    printf(“\n”);}
    if(word[0]==’E’){
    if(word[1]’X’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[1]==’X’){
    if(word[2]’E’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[2]==’E’){
    if(word[3]’R’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[3]==’R’){
    if(word[4]’C’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[4]==’C’){
    if(word[5]’I’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[5]==’I’){
    if(word[6]’S’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[6]==’S’){
    if(word[7]’E’){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[7]==’E’){
    if (word[8]>0){printf(“%s is between EXERCISE and MUSCLES.\n”,word);
    printf(“\n”);}}}}}}}}}
    if(word[0]==’M’){
    if(word[1]’U’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[1]==’U’){
    if(word[2]’S’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[2]==’S’){
    if(word[3]’C’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[3]==’C’){
    if(word[4]’L’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[4]==’L’){
    if(word[5]’E’){printf(“%s is comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[5]==’E’){
    if(word[6]’S’){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}
    if(word[6]==’S’){
    if (word[7]>0){printf(“%s comes after MUSCLES.\n”,word);
    printf(“\n”);}}}}}}}}}
    return 0;}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s