题解 | #牛牛的替换#
牛牛的替换
https://www.nowcoder.com/practice/f2a107dbb99243798d3048a672e8f747
知识点:
函数:函数
#include <iostream> using namespace std; void replace(char* arr, int n, char o, char r); int main() { int n; char a1, a2, a3, a4; cin >> n >> a1 >> a2 >> a3 >> a4; char arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } replace(arr, n, a1, a2); replace(arr, n, a3, a4); for (int i = 0; i < n; i++) { cout << arr[i]; } cout << endl; return 0; } void replace(char* arr, int n, char o, char r) { for (int i = 0; i < n; i++) { if (arr[i] == o) { arr[i] = r; } } }#算法#