标点同字母处理,如“I am a student." --> "student. a am I"
整个字符串逆序再没个单词逆序。
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- void swap(char s[],int l,int r)
- {
- char s1;
- while(l<r)
- {
- s1=s[l];
- s[l]=s[r];
- s[r]=s1;
- l++;
- r--;
- }
- }
- int main()
- {
- int i,l,j;
- char s[101];
- gets(s);
- l=strlen(s);
- swap(s,0,l-1);
- j=0;
- for(i=0; i<l; i++)
- {
- if(s[i]==' ')
- {
- swap(s,j,i-1);
- j=i+1;
- }
- if(i==l-1)
- swap(s,j,l-1);
- }
- puts(s);
- return 0;
- }