题解 | #字符串操作#
字符串操作
https://www.nowcoder.com/practice/06a5336b64e3481fbbcc1f7d5cba548d
#include<stdio.h>
int main() {
int n, m, i, a, b;
char x,y;
scanf("%d %d", &n, &m);
char c[n];
scanf("%s", &c);
while (m!=0&&(scanf("%d %d %c %c", &a, &b, &x, &y) != EOF)) {
for (i = a-1; i < b; i++) {
if (c[i] == x) {
c[i] = y;
}
}
m--;
}
printf("%s", c);
}
int main() {
int n, m, i, a, b;
char x,y;
scanf("%d %d", &n, &m);
char c[n];
scanf("%s", &c);
while (m!=0&&(scanf("%d %d %c %c", &a, &b, &x, &y) != EOF)) {
for (i = a-1; i < b; i++) {
if (c[i] == x) {
c[i] = y;
}
}
m--;
}
printf("%s", c);
}