Title address
Novice in asking big inspiration, thank you! (string into a char array can ac, don't understand why can't use string)
#include
#include
#include
#include
# define ll long long
using namespace std;
Void delchar (int pos, string & amp; S)
{
Int len=s.l ength ();
For (int I=pos. i
S=s [I - 1] [I];
}
S [len - 1]='\ 0';
}
Int main ()
{
Int k, pos, CNT=1;
string s;
Cin> k;
While (k -)
{
Cin> Pos.
Cin> s;
Delchar (pos, s);
cout
}
}
CodePudding user response:
Because your test environment is the C language, not a C + +, on the other hand, if the replacement into a char, then delchar function of s.l ength (); How to deal with?CodePudding user response:
GCC is a C language compilerCodePudding user response:
Didn't you watch the output is correct and meet the requirements of the subject? Output and proved by the requirement,
Int k, pos, CNT=1;
The string s, ss;
cin> k;
While (k -)
{
cin> Pos.
cin> s;
Delchar (pos, s);
Ss +=cnt++ + '0'.
Ss +=' ';
Ss +=s;
Ss +='\ n';
}
cout
CodePudding user response:
Two questions1 the string header file is not a string starting with c cstrings corresponding c language string. H
2 string is not 0 0 at the end or not regulations end so s [len - 1]='\ 0'; Cannot be guaranteed to be effective
The final output to cout
CodePudding user response: