Blue Bridge Cup ALGO-110 string expansion (String)

Source: Internet
Author: User

"Idea": follow the test instructions to the line. Note the difference between the letter string and the number string when p1=2. It is recommended to use a string, replacing the line with the Replace function, char[] to move large amounts of data.

"AC Code":

#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include < cstring>using namespace std; #define MAX 10000+5int Islower (char c) {if (C >= ' a ' && c <= ' z ') return 1;retu RN 0;} int Isnum (char c) {if (c >= ' 0 ' && C <= ' 9 ') return 1;return 0;} void reverse (char repstr[]) {int i = 0;for (i = 0; i < strlen (REPSTR)/2; i++) {char temp;temp = repstr[i];repstr[i] = Rep Str[strlen (REPSTR) -1-i];repstr[strlen (repstr) -1-i] = temp;}} int main () {freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); int p1 = 0, p2 = 0, p3 = 0, i = 0, j = 0, k = 0;s Tring str;//inputcin >> p1 >> p2 >> p3;cin >> str;//handlefor (i = 1; i < str.length () 1; i++) Note Scope {if ('-' = ' = Str[i]) {int flag = 0;char repstr[max];if (islower (str[i-1]) && islower (str[i+1]) && str [i+1]>str[i-1]) flag = 1;else if (Isnum (str[i-1]) && isnum (str[i+1]) && str[i+1]>str[i-1]) flag = 2; if (0==FLAG) continue;//replace p1 p2 int cnt = 0;for (j = str[i-1]+1; J < str[i+1]; J + +) {for (k = 0; k < P2; k++) {if (1 = = p1) {Repst r[cnt++] = j;} else if (2 = = p1) {if (1 = = flag) repstr[cnt++] = j+ ' A '-' a '; else if (2 = = flag) repstr[cnt++] = j;} else if (3 = = p1) {repstr[cnt++] = ' * ';}}} REPSTR[CNT] = ' + ';//p3if (2 = = p3) reverse (REPSTR);//replacestring rep = Repstr;str.replace (i, 1, Rep);}} Outputcout << Str;return 0;}

Note:

Common functions of the 1.c++string class

2. Conversion between string and char* char[]


Blue Bridge Cup ALGO-110 string expansion (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.