题解 | #牛牛的替换#
牛牛的替换
https://www.nowcoder.com/practice/f2a107dbb99243798d3048a672e8f747
#include <stdio.h> int main() { int n = 0; char a1 = 0; char a2 = 0; char a3 = 0; char a4 = 0; scanf("%d %c %c %c %c", &n, &a1, &a2, &a3, &a4); getchar();//吸收换行符 char str[100] = { 0 }; for (int i = 0; i < n; i++) { scanf("%c", &str[i]); if (str[i] == a1) { str[i] = a2; } if (str[i] == a3) { str[i] = a4; } //吸收换行符 } //输出 printf("%s\n", str); return 0; }