NOIP2007 the expansion of a string

Source: Internet
Author: User

NOIP2007 's second topic, the personal feeling is violence to run simulation just fine, the data range is allowing us to run the program

Title Summary: The topic will give you three keywords P1,P2,P3, for different keywords will be on your program request, next will give you a string, which contains a-z,a-z,0-9, and minus-, we need to do is to press P1,P2,P3 request for "-" The specific requirements for P1,P2,P3 are as follows:

(1) The following situation is required to do the expansion of the string: in the input string, there is a minus "-", minus both sides of the same lowercase letters or the same number, and in the Order of ASCII code, the right character of the minus sign is strictly greater than the left character.

(2) parameter P1: expansion mode. P1=1, for the word mother and child string, filled with lowercase letters, p1=2, for the character string, filled with uppercase letters. In both cases, the number substring is populated in the same way. When P1=3, both the substring and the number substring are populated with the asterisk "*" with the same number of letters to fill.

(3) parameter P2: The number of repetitions of the fill character. P2=k indicates that the same character is to be continuously populated with K. For example, when P2=3 , the substring "d-h" should be extended to "Deeefffgggh". The characters on both sides of the minus sign do not change. (4) Parameter P3: Whether or not to reverse: p3=1 means to maintain the original order, p3=2 is to use reverse output, note that this still does not include the characters at both ends of the minus sign. For example, when P1=1, p2=2, p3=2, the substring "d-h" should be extended to "Dggffeeh".

(5) If the character to the right of the minus sign is exactly the successor to the left character, delete the middle minus sign only, for example: "D-e" should output for "de", "3-4" should be output as "34". If the character to the right of the minus sign is less than or equal to the left character in ASCII order,
Output, to retain the middle of the minus sign, for example: "d-d" should be output as "d-d", "3-1" should be output as "3-1".

This depends on you to run the simulation technology, how to classify the same type, minimize code length, clear thinking is the key, first of all, the most easy to deal with the parts out, is only the output minus or do not output part of the Special award, then I first to P3 classification, the decision is positive or reverse output, followed by P1 judgment, For case changes, the P2 is ok as long as the loop is done at the output.

Here are some details:

(1) First we are not able to read the output, we have to put the answer in an out array, if we consider extreme situations such as a-za-za-za-z ... At most 33 groups, when the P2 is taken to the maximum of 8, then the result length will not be less than 33 * 24 + 8 + (100-3) = 6403, the array must be large enough to open.

(2) There is a pit in the data, such as a a-4,6-p,a--c this, must be careful, I also WA 3 times just A, it is not easy AH

#include <algorithm>#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>using namespaceStd;typedefLong Longll;BOOLNumberChar);voidInsertChar,Char);Char inch[ the], out[7000];intP1,p2,p3,len =-1;intMain () {scanf ("%d%d%d",&p1,&p2,&p3); Cin.Get(); scanf ("%s",&inch);  out[++len] =inch[0];  for(inti =1; I < strlen (inch); ++i)if(inch[I] = ='-') Insert (inchI1],inch[i +1]); Else              out[++len] =inch[i]; Puts ( out); return 0;}BOOLNumberCharx) {    if(x <='9'&& x >='0')            return 1; return 0;}voidInsertCharBeginCharend) {    if(Begin +1= = end)return ; if(Begin >=end) {         out[++len] ='-'; return ; }    if(Begin = ='-'){         out[++len] ='-'; return ; }    if(End = ='-'){         out[++len] ='-'; return ; }    if(Begin &&!)Number (end)) {         out[++len] ='-'; return; }    if(P1 = =3){         for(inti = begin +1; i < end; ++i) for(intj =0; J < P2; ++j) out[++len] ='*'; return ; }    if(number (begin)) {if(P3 = =1)             for(inti = begin +1; i < end; ++i) for(intj =0; J < P2; ++j) out[++len] =i; Else              for(inti = end-1; i > begin; --i) for(intj =0; J < P2; ++j) out[++len] =i; }    Else{        if(P3 = =1)             for(inti = begin +1; i < end; ++i) for(intj =0; J < P2; ++j)if(P1 = =1) out[++len] =i; Else              out[++len] = i-'a'+'A'; Else              for(inti = end-1; i > begin; --i) for(intj =0; J < P2; ++j)if(P1 = =1) out[++len] =i; Else              out[++len] = i-'a'+'A'; }    return ;}

NOIP2007 the expansion of a string

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.