main.cpp
来自「我做的一些C语言练习题,里面一共有76道题目,主要用到一些计算机常用的算法,如:」· C++ 代码 · 共 45 行
CPP
45 行
/*********************************************************************************
7. 读入一行文本,包含若干个单词(以空格间隔,%结尾)。将其中以 A 开头的
单词与以 N 结尾的单词,用头尾交换的办法予以置换。
例子:
Never frown even when you are sad because you never know who is falling in love with your smile
置换后为:
Never nrowf nvee nhew you era sad because you never know who is falling ni love with your smile
********************************************************************************/
#include <stdio.h>
void main()
{
char *s,*t;
char str[] = "Never frown even when you are sad because you never know who is falling in love with your smile%";
s = t = str;
while(*t != '%')
{
while(*t == ' ')
printf("%c",*t++);
s = t;
while(*t != ' ' && *t != '%')
t++;
if(*s == 'a' || *(t-1) == 'n')
{
if(s != t-1)
{
char temp;
temp = *s;
*s = *(t-1);
*(t-1) = temp;
}
}
while(s != t)
{
printf("%c",*s++);
}
}
printf("\n");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?