1 条题解

  • 0
    @ 2025-2-14 20:52:09

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 209;
    string s[N];
    
    void solved() {
    	int n = 1;
    	
    	while(cin >> s[n]) n ++;
    	n --;
    	
    	for(int i = 1; i <= n - 2; i ++) {
    		if(s[i] == s[n - 1]) s[i] = s[n];
    	}
    	
    	for(int i = 1; i <= n - 2; i ++) {
    		if(i > 1) cout << ' ';
    		cout << s[i];
    	}
    	
    	return ;
    }
    int main() {
    	cout << fixed << setprecision(5);
    	int t = 1;
    	// cin >> t;
    	
    	while(t --) solved();
    	
    	return 0;
    }
    

    Python :

    # coding=utf-8
    # 输入字符串 s
    s = input()
    
    # 输入待替换的单词 a
    a = input()
    
    # 输入将替换成的单词 b
    b = input()
    
    # 使用字符串的 replace 方法进行替换
    result = s.replace(a, b)
    
    # 输出替换后的字符串
    print(result)
    
    
    • 1

    信息

    ID
    501
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者