UVa483 - Word Scramble

#include 
#include 

#define N 100

void rev(char *str)
{
    int i, len = strlen(str);

    for (i = 0; i < len / 2; i++) {
        str[i] = str[i] ^ str[len - 1 - i];
        str[len - 1 - i] = str[len - 1 - i] ^ str[i];
        str[i] = str[i] ^ str[len - 1 - i];
    }
}

int main()
{
    int ch;
    char buf[N];
    int len = 0;

    #ifndef ONLINE_JUDGE
        freopen("d:\\UVa\\uva_in.txt", "r", stdin);
    #endif

    while ((ch = getchar()) != -1) {
        if (' ' == ch || '\n' == ch) {
            if (len) {
                buf[len] = '\0';
                rev(buf);
                printf("%s", buf);
            }
            putchar(ch);
            len = 0;
        } else {
            buf[len++] = ch;
        }

    }
    return 0;
}

你可能感兴趣的:(#,uva)