题目:
将一句话里的单词导致,标点符号不倒换。例如一句话,"I come from Tianjin.",倒换后的结果为"Tianjin. from come I"。
Code(C):
#include<stdio.h> #include<string.h> void change(char *s); reverse(char *s,int start,int end); void main() { char s[50]; printf("请输入字符串\n"); gets(s); change(s); printf("到之后的字符串为%s\n",s); } void change(char *s) { int len,start,end,i; len = strlen(s); start = 0; end = len-1; reverse(s,end); end = 0; for(i = 0;i < len;) { if(s[i] != ' ') { start = i; while(s[i] != ' ' && s[i] != '\0') i++; i = i-1; end = i; reverse(s,end);; } i++; } } reverse(char *s,int end) { char temp; while(start < end) { temp = s[start]; s[start] = s[end]; s[end] = temp; start++; end--; } }