标签:margin == memory ever while 杂志 剑指offer bsp offer
转载请注明出处:http://blog.csdn.net/ns_code/article/details/27372033
Cat对一一的翻转这些单词顺序可不在行,你能帮助他么?
student. a am I I‘m a Freshman and I like JOBDU!
I am a student. JOBDU! like I and Freshman a I‘m
代码例如以下:
#include<stdio.h> void Swap(char *a,char *b) { char temp = *a; *a = *b; *b = temp; } /* 反转字符串 */ void Reverse(char *str,char *begin,char *end) { if(str==NULL || begin==NULL || end==NULL) return; while(begin < end) { Swap(begin,end); begin++; end--; } } /* 反转单词顺序 */ void ReverseSentence(char *str) { if(str == NULL) return; char *begin = str; char *end = str; while(*end != ‘\0‘) end++; end--; //反转整个字符串 Reverse(str,begin,end); //反转每一个单词 begin = str; while(*begin == ‘ ‘) begin++; end = begin; while(*begin != ‘\0‘) { while(*end!=‘ ‘ && *end!=‘\0‘) end++; end--; Reverse(str,begin,end); //跳过多个空格 end++; while(*end == ‘ ‘) end++; begin = end; } } int main() { char str[50000]; while(gets(str) != NULL) { ReverseSentence(str); puts(str); } return 0; }
/**************************************************************
Problem: 1361
User: mmc_maodun
Language: C
Result: Accepted
Time:50 ms
Memory:912 kb
****************************************************************/
姑且贴上吧,一点点进步。日后回来再做个对照!
标签:margin == memory ever while 杂志 剑指offer bsp offer
原文地址:http://www.cnblogs.com/clnchanpin/p/6916757.html