UVa483 - Word Scramble

原创 2012年03月31日 15:38:14
#include <stdio.h>
#include <string.h>

#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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

Scramble String

Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to t...

Scramble String

Q: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty ...

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

Scramble String

Problem: Given a string s1, we may represent it as a binary tree by partitioning it to two non-...

Scramble String

题目 Given a string s1, we may represent it as a binary tree by partitioning it to two non-em...

Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substri...

Scramble String

先贴一个直观的解法:递归,但是数据比较大时会超时 class Solution { public:     bool sameChars(const string& s1,const string& ...

Scramble String

https://oj.leetcode.com/problems/scramble-string/ 超时的答案:

Scramble String

题目描述: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty...

Scramble String

-----QUESTION----- Given a string s1, we may represent it as a binary tree by partitioning it...

[leetcode] Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)