Sunday, February 27, 2011

483 - Word Scramble


#include<stdio.h>
int strLen(char[]);
void strRev(char[]);
int main()
{
    char word[100],ch;
    //freopen("in.txt","r",stdin);
    while(scanf("%s",word)==1)
    {
        scanf("%c",&ch);
        strRev(word);
        printf("%s%c",word,ch);
    }
    return 0;
}
int strLen(char str[])
{
    int i;
    for(i=0;str[i]!='\0';i++);
    return i;
}
void strRev(char str[])
{
    int i,l=strLen(str),n=l/2;
    char ch;
    for(i=0;i<n;i++)
    {
        ch=str[i];
        str[i]=str[l-i-1];
        str[l-i-1]=ch;
    }
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.