Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )
Note: Total time limit: 1000ms memory limit: 65536kB,
Describe
The number of characters with two strings of STR and SUBSTR,STR not exceeding 10,SUBSTR is 3. (The number of characters does not include ' + ' at the end of the string.) Insert the substr into the one of the most ASCII characters in Str, and if there are more than one, only the first one is considered.
Input
The input includes several lines , each of which behaves as a set of test data, in the form
STR substr
Output
For each set of test data, the output is inserted after the string.
Sample input
Abcab eee12343 555
Sample output
abceeeab12345553
1#include <iostream>2#include <string>3 intMain ()4 {5 using namespacestd;6 Charstr[ -], substr[4];7 while(Cin >> STR >>substr)8 {9 intMax =0;Ten CharMaxstr = str[0]; One intS1 = strlen (str);//find out the actual length of the str,substr array. A intS2 =strlen (substr); - if(S1 >Ten|| S2! =3) -cout <<"error!"<<Endl; the Else - { - for(inti =0; I<S1 +1; i++) - if(str[i]>maxstr) { +Maxstr =Str[i]; -Max =i; + } A for(inti =0; I < Max +1; i++) at { -cout <<Str[i]; - } - for(inti =0; i < S2; i++) -cout <<Substr[i]; - for(inti = max +1; I < S1 +1; i++) incout <<Str[i]; -cout <<Endl; to } + } - return 0; the}
The result is right, but to OJ above is complete error .... However, sooner or later will find the problem, there is great God found the problem, hope to be able to advise, grateful:)
Final Exam-Programming Question # # #: String insertion