标签:
输入 i come from tianjin. 输出 tianjin. from come i
int main()
{
int i = 0, j = 0, flag = 0, begin, end;
char str[] = "i come from tianjin.";
char temp;
j = strlen(str) - 1;
printf("%s\n", str);
while (j > i)//逆序整个子串
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
j--;
i++;
}
printf("%s\n", str);
i = 0;
while (str[i])
{
if (str[i] != ‘ ‘)
{
begin = i;
while (str[i] && str[i] != ‘ ‘)
{
i++;
}
i = i - 1;//这的处理很重要
end = i;
}
cout << begin << " "<<end<<endl;
while (end > begin)//逆序单词
{
temp = str[end];
str[end] = str[begin];
str[begin] = temp;
begin++;
end--;
}
i+=1;//i在递增
}
printf("%s\n", str);
cin.get();
return 0;
}
标签:
原文地址:http://www.cnblogs.com/ranranblog/p/5617456.html