标签:style blog color for io div
//将字符串反转,但单词不倒置。 #include<stdio.h> #include<string.h> void reverse(char *s) { char data[255][255];//将s中的空格和非空格子串进行存储 int row = 0,column = 0; int i,j,k; for(i=0;s[i];) { data[row][column] = s[i]; column++; //找到了空格子串的开头 if(s[i] == ‘ ‘) { i++; if(s[i] == ‘ ‘) { do { data[row][column++] = s[i++]; }while(s[i] == ‘ ‘); data[row++][column] = ‘\0‘; column = 0; } else { data[row++][column] = ‘\0‘; column = 0; } } //找到了非空格子串的开头 else if(s[i] != ‘ ‘) { i++; if(s[i] != ‘ ‘) { do { data[row][column++] = s[i++]; }while(s[i] != ‘ ‘ && s[i]);//注意非空格字符还包括字符串结束符。 data[row++][column] = ‘\0‘; column = 0; } else { data[row++][column] = ‘\0‘; column = 0; } } } //将data[][]里面的子串存放于s中。 k = 0; for(i=row-1;i>=0;i--) { for(j=0;data[i][j]!=‘\0‘;j++) { s[k++] = data[i][j]; } } s[k] = ‘\0‘; } int main() { char s[255]; gets(s); reverse(s); puts(s); }
将字符串反转,但单词不倒置。Right here waiting for you! -> you! for waiting here Right,布布扣,bubuko.com
将字符串反转,但单词不倒置。Right here waiting for you! -> you! for waiting here Right
标签:style blog color for io div
原文地址:http://www.cnblogs.com/Camilo/p/3838118.html