Home > Back-end >  Enter a string (length is less than 20), cut from the middle into two series such as 12345678 divide
Enter a string (length is less than 20), cut from the middle into two series such as 12345678 divide

Time:09-19

, ah, online answer Ann

CodePudding user response:

For example

 int main (int arg c, const char * argv []) {
TMP char buf [21], [11];
int len;
The fgets (buf, sizeof (buf), stdin);
Len=(int) strlen (buf);
If (buf [len - 1]=='\ n') {
Buf [len -]='\ 0';
}
Len/=2;
Strncpy (TMP, buf, len);
Printf (" % s % s ", TMP, buf + len);
return 0;
}

CodePudding user response:

In c + +/2 directly is short after long before the break up,

CodePudding user response:

CodePudding user response:

 
#include
#include
using namespace std;

Int main () {
String STR.

Cin & gt;> str;

Auto mid=STR. The begin () + STR. The length ()/2;

String s1 (STR. The begin (), mid);
String s2 (mids, STR. End ());

Cout & lt;
return 0;
}

/*
Run
Abcdefg
ABC, defg
*/
  • Related