String (MFC) in C + +

Source: Internet
Author: User

Title: UVALive-6439 Https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ problem&problem=4450

Test instructions: Enter an integer t, representing the number of times the program tests, and then to replace some non-palindrome string to form a palindrome string, to form the maximum length of palindrome string.

For example, Abdab-a non-palindrome string but replace AB with another character * so that the *d* maximum is 3, so the final result output 3.

Before you do this, learn about the use of string in C + +.

1.

String is included in the header file <string> Remember that it is not a CString or a string.h, but another header file string

and need to add using namespace std; The namespace

2.

String is a class that is already defined in the C + + language and belongs to a class.

So there is a constructor and destructor,

Assume

String str; DECLARE first

string (int n,int c); ------>>>> function is to assign a constructor to Str to copy is n C is a string

For example str.string (3, ' # '); Then output str is # # #//three X

There is also a string (const char *p)-----> Copy Construction Assignment

For example: str.string ("* * * *"); So the output str s * * * *

3.

Here is the key to solving problems,

String L= "", r= ""; Empty content

L=l+ ' a '; The content of L is a

The content of l=l+ ' B '/L is AB

The content of l=l+ ' d '/L is ABD

And so on

String s= "abc";

S= ' G ' +s; The content of S is gabc

s= ' y ' +s; The content of S is ygabc

etc. (The main explanation here is that the addition is a string connection, before and after the addition of the next see)

AC Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#define MAX (a) > (b) ( A):(B))
#define MIN (a) < (b) ( A):(B))
#define SWAP (a,b,t) t=a,a=b,b=t
#define MEM0 (x) memset (x,0,sizeof (x))
#define MEM1 (x) memset (x,-1,sizeof (x))
#define MEMX (x) memset (x,0x3f,sizeof (x));
using namespace Std;
typedef long Long LL;
const int inf=0x3f3f3f;
const double eps=1e-12;
Char str[50010];
int main ()
{
int t,cnt=0;
cin>>t;
while (t--) {
cin>>str;
int ans=0;
String L= "", r= "";
int Len=strlen (str);
int MID=LEN/2;
for (int i=len-1;i>=mid;i--) {
L=l+str[len-1-i];
R=str[i]+r;
if (l==r&&len-1-i!=i) {
ans+=2;
L.clear ();
R.clear ();
}
if (I==len/2&&!l.empty ())
ans++;
}
printf ("Case #%d:%d\n", ++cnt,ans);
}
return 0;
}

String (MFC) in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.