It will replace the string specified in the text file into a new string. OJ temporarily due to the current system can not support the user reads the file, we write programs from the keyboard input file contents, when a behavior input end, indicating the end. There are two strings behind the end, the second string with the required replacement text all first string.
Input formats:
Xi’an Institute of Posts and Telecommunications is co-designed and implemented by the People’s Government of Shaanxi Province and the Ministry of Industry and Information Technology. The Institute is located in Xi’an, a historic city in Northwest China, famous for its magnificent ancient culture.
end (indicating the end)
Institute (first string, the second string with the required replacement)
University (second string)
Output formats:
Xi’an University of Posts and Telecommunications is co-designed and implemented by the People’s Government of Shaanxi Province and the Ministry of Industry and Information Technology.The University is located in Xi’an, a historic city in Northwest China, famous for its magnificent ancient culture.
Sample input:
Xi’an Institute of Posts and Telecommunications is co-designed and implemented by the People’s Government of Shaanxi Province and the Ministry of Industry and Information Technology.
The Institute is located in Xi’an, a historic city in Northwest China, famous for its magnificent ancient culture.
end
Institute
University
Sample output:
Xi’an University of Posts and Telecommunications is co-designed and implemented by the People’s Government of Shaanxi Province and the Ministry of Industry and Information Technology.The University is located in Xi’an, a historic city in Northwest China, famous for its magnificent ancient culture.
#include<iostream> #include<cstring> using namespace std; int main() { string a,b,c,m; getline(cin,a); while(1) { getline(cin,m); if(m=="end"){ break; } a+='\n'; a+=m; } a+='\n'; getline(cin,b); getline(cin,c); int found; found=a.find(b); while(found!=-1) { a.replace(found,b.size(),c); found=a.find(b,found+1); }cout<<a; return 0; }