//面试碰到的一道题,"she is a girl"字符串倒置成"girl a is she",给我一张纸就让我写程序,然后就成功的被pass掉了。程序真的不是在纸上写出来的。
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char str[] = "she is a girl"; char *tmp = (char*)malloc(strlen(str) + 1); memset(tmp,strlen(str)+1); int count = 0; char * p = str; while(strsep(&p," ")) count++; while(count--){ p = str; for(int i = 0;i<count;i++) p+=(strlen(p)+1); if(count == 0) strcat(tmp,p); else strcat(strcat(tmp,p)," "); } puts(tmp);//"girl a is she" free(tmp); return 0; }原文链接:https://www.f2er.com/javaschema/286226.html