输入字符串“I am a student”,要求输出字符串“student a am I”

来源:互联网 发布:人工智能学什么专业 编辑:程序博客网 时间:2024/05/16 13:45

面试题目: 输入字符串“I am a student”,要求输出字符串“student a am I”

#include <stdio.h>

void  main()
{
    char src[] = "I am a stdutent";
    char *temp_start = src;
    char *temp_end = src;
    while (*temp_end != '\0')
    {
        temp_end++;
    }
    temp_end--;
    char temp;
    while (temp_start < temp_end)
    {
        temp = *temp_start;
        *temp_start = *temp_end;
        *temp_end = temp;
        temp_start++;
        temp_end--;
    }
    //reverseal all

    char *index = src;
    printf("The src value is %s\n", src);
    
    while (true)
    {
        temp_start = index;
        while (*index != '\0' && *index != ' ')
        {
            ++index;
        }
        temp_end = --index;
        index++;

        while (temp_start < temp_end)
        {
            temp = *temp_start;
            *temp_start = *temp_end;
            *temp_end = temp;
            temp_start++;
            temp_end--;
        }
        if (*index != '\0')
        {
            ++index;
        }
        else
        {
            break;
        }

    }

    printf("The src value is %s\n", src);

}
阅读全文
0 0
原创粉丝点击