It seems like a simple question, but there are many errors.
The requirement for a question is to convert a string of letters into a URL, in the format of http (ftp): // xxx.ru/xxxx. it seems simple, but it is easy to make mistakes.
When I first started searching, I searched for the first group of http/ftp, and then searched for the first ru to form the website. However, an error was reported. The following is an example: httpruc
Therefore, you cannot search for the first website. That is to say, it is illegal to avoid having nothing before. ru. Note that http is a four-character ftp with only three characters, so it cannot be fixed ..
# Include <iostream> # include <string> using namespace std; int main () {string tar, res; string tarstack; int propos = 0, ctpos = 0; cin> tar; if (tar [0] = 'H') {tarstack = "http";} if (tar [0] = 'F ') {tarstack = "ftp";} ctpos = tar. find ("ru", tarstack. length () + 1); // 5 is not acceptable. Inertial thinking cannot be performed if (tar [0] = 'H') {cout <tarstack <": // "; for (int I = 4; I <ctpos; I ++) {cout <tar [I] ;}cout <". ru "; if (ctpos + 2 = tar. length () cout <endl; else {cout <"/"; for (int I = ctpos + 2; I <tar. length (); I ++) {cout <tar [I];} cout <endl ;}} else if (tar [0] = 'F ') {cout <tarstack <": //"; for (int I = 3; I <ctpos; I ++) {cout <tar [I];} cout <". ru "; if (ctpos + 2 = tar. length () cout <endl; else {cout <"/"; for (int I = ctpos + 2; I <tar. length (); I ++) {cout <tar [I] ;}cout <endl ;}return 0 ;}// example: httpruhhphhhpuhruruhhpruhhphruhhru