- 题目描述:
-
请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
- 输入:
-
每个输入文件仅包含一组测试样例。
对于每组测试案例,输入一行代表要处理的字符串。
- 输出:
-
对应每个测试案例,出经过处理后的字符串。
- 样例输入:
-
We Are Happy
-
We%20Are%20Happy
样例输出:
【解题思路】简单题目,逐个输入字符,知道遇到回车停止输入,如中途遇到空格,将空格替换成对应的字符串“%20”输出即可。
AC code:
#include <cstdio> using namespace std; int main() { char c; scanf("%c",&c); char cc[4]="%20"; while(c!=' ') { if(c!=' ') printf("%c",c); else printf("%s",cc); scanf("%c",&c); } return 0; }