把这个字符串God Skin 转换成 doG nikS 有没有会写这个简单的算法的
1条回答 默认 最新
_GX_ 2022-03-01 01:28关注#include <stdio.h> #include <ctype.h> void swap(char *p, char *q) { char t = *p; *p = *q; *q = t; } void reverse_impl(char *first, char *last) { while (first < last) swap(first++, --last); } void reverse(char *s) { while (*s) { char *p = s; while (*p && isblank(*p)) p++; char *q = p; while (*q && !isblank(*q)) q++; reverse_impl(p, q); s = q; } } int main(int argc, char *agv[]) { char s[] = "God Skin"; reverse(s); printf("%s\n", s); return 0; }$ gcc -Wall main.c $ ./a.out doG nikS评论 打赏 举报解决 1无用