题解 | #字符串操作#
字符串操作
https://www.nowcoder.com/practice/06a5336b64e3481fbbcc1f7d5cba548d
#include <stdio.h> # pragma warning(disable:4996) void jiaohuan(char* c, int l, int r, char c1, char c2); int main() { int n, m, i, l, r; char c1, c2; char c[100]; scanf("%d %d", &n, &m); scanf("%s", c); for (i = 1; i <= m; i++) { scanf("%d %d %c %c", &l, &r, &c1, &c2); jiaohuan(c, l, r, c1, c2); } printf("%s", c); return 0; } void jiaohuan(char* c, int l, int r, char c1, char c2) { int t; for (t = l - 1; t < r; t++) { if (c[t] == c1) c[t] = c2; } }