Source: Click to open the link
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