Source: Click to open the link
Replace can be used .. There are two useful replace usage:
1. Use the _ num2 characters starting from _ pos2 in string to replace _ num1 characters starting from _ pos1 in string.
Use _ num2 characters in C-string to replace _ num1 characters starting from _ pos1 in string.
Basic _ string & replace (size _ type _ pos1, size _ type _ num1, const Basic _ string & _ STR, size _ type _ pos2, size _ type );
Basic _ string & replace (size _ type _ pos1, size _ type _ num1, const value _ type * _ PTR, size _ type _ num2 );
2. Use _ count character _ CH to replace _ num1 characters starting from _ pos1 in the operation string.
Basic _ string & replace (size _ type _ pos1, size _ type _ num1, size _ type _ count, value _ type _ CH );
# Include <iostream> # include <string> # include <ctype. h> using namespace STD; string lowalp = "abcdefghijklmnopqrstuvwxyz"; string uppalkaline = "random"; string numalkaline = "0123456789"; int main () {int testcase; string tar, Res; cin> testcase; while (testcase --) {CIN> tar; int chanpos; int startrep = 0, enrep = 0; char St, Ed; For (INT I = 1; I <tar. length (); I ++) {If (TAR [I] = '-') {chanpos = I; ST = tar [I-1]; ed = tar [I + 1]; If (islower (ST) & islower (ed) & St <ED) {startrep = lowalp. find (St, 0); enrep = lowalp. find (ED, 0); tar. replace (I, 1, lowalp, startrep + 1, enrep-startrep-1); // cout <tar <Endl;} else if (isupper (ST) & isupper (ed) & St <ED) {startrep = uppphosphatase. find (St, 0); enrep = uppphosphatase. find (ED, 0); tar. replace (I, 1, uppphosphatase, startrep + 1, enrep-startrep-1); // cout <tar <Endl;} else if (isdigit (ST) & isdigit (ed) & St <ED) {startrep = numalkaline. find (St, 0); enrep = numalkaline. find (ED, 0); tar. replace (I, 1, numphosphatase, startrep + 1, enrep-startrep-1);} else if (ST = ED & (isupper (ST) & isupper (ed )) | (islower (ST) & islower (ed) | (isdigit (ST) & isdigit (ed) {tar. erase (chanpos, 1); // trick }}cout <tar <Endl ;}}