Simple algorithm programming question - output any paragraph in reverse order of words

Throw this question to the owner of Wenzhou Leather Shoe Factory. The boss directly said that the original intention of this question is to ask you to propose a stack solution .

  what?stack?too low!

  Because of such a problem, it is a bit big to implement a stack. In fact, who doesn't know that you can push words into it, and then pop it out? Therefore, the stack solution is too general and not worth mentioning. …Toss with this kind of problem when I have nothing to do on weekends, it is not wrong, it is wrong to wake up the lunatic and Xiaoxiao when the mosquito net is opened to sleep, and things will occasionally become serious.

  In addition, using C language is completely different from using Java. Java calls ready-made classes will be very simple, and the complexity is completely hidden inside. In addition, whether C language can use strtok must also be restricted. The following is my program, very fun, people like me who don't know how to program, please don't laugh at me. Because I didn't use strlen, didn't use strcpy, didn't use malloc...:

#include <stdio.h>
#include <stdlib.h>

int ok(char c)
{
        if ( (c <= 90 && c >= 65) || (c <=122 && c >= 97) )
                return 1;
        return 0;
}

int main(int argc, char **argv)
{
        char orig[] = {'i', ' ', 'a', 'm', ' ', 'a', ' ', 's', 't', 'u', 'd', 'e', 'n', 't', ',', 'a', 'n', 'd', ' ', 'y', 'o', 'u', 0};

        char *buf = orig, *tbuf = orig;
        int i = 0, j = 0;
    // 获取长度
        while (*tbuf++ != 0) j++;

    // 前后逆序交换
        for (j--; j > i; i++, j--) {
                char c = orig[i];
                orig[i] = orig[j];
                orig[j] = c;
        }

    // 遍历
        while (*buf != 0) {
                int k = 0, p = 0;
                char *temp = buf;
                while (ok(*(buf++))) {
                        k++;
                }
        // 按照单词逆序
                for (k--; p < k; p++, k--) {
                        char c = temp[p];
                        temp[p] = temp[k];
                        temp[k] = c;
                }
        }
    // 打印结果
        printf("%s\n", orig);
}

It looks like a mandarin duck butterfly, it should not be the age. Um? What shouldn't it be?

  Not much to say.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325552800&siteId=291194637