Simple string simulation questions and simple string simulation questions

Source: Internet
Author: User

Simple string simulation questions and simple string simulation questions
Problem 2183 simple questionAccept: 48 Submit: 236
Time Limit: 1000 mSec Memory Limit: 32768 KB Problem Description

There are some simple compressed strings. For example, a [120] represents 120. For the string acb [3] d [5] e

Now we will give you two strings, cString and nString. One is a compressed string, and the other is not compressed.

Determine whether nString is a substring of cString. If it is True, otherwise False is output. the cString length clen range is 0 <clen <1000, and the nlen range of nString length is 0 <nlen <1000; cString only contains 26 lowercase letters, [], number (greater than 0 and less than 10 ^ 9 ). NString only contains 26 lower-case letters.

Sample Inputacb [3] d [5] ebd Sample OutputTrue Source

FOJ prize-winning monthly round-September


At first, I got an error and didn't know why. Later I found that the while (scanf ("% s", str1, str2) is missing )! = EOF) I feel cheated.

The idea of this question:

It is to separate the numbers and characters, and then you can judge it.

# Include <stdio. h> # include <string. h> char str1 [1500], str2 [1500]; char string1 [1234567], string2 [1234567]; // I is the starting position of the number, and j is the ending position of the number; used to calculate the number of string a; int change (int I, int j) {int ans = 0, l = 1; for (int k = j; k> = I; k --) {ans + = (str1 [k]-'0') * l; l = l * 10;} return ans;} int main () {int l1, l2; int I, j, k = 0; while (~ Scanf ("% s", str1, str2) {l1 = strlen (str1); l2 = strlen (str2); int num1 [1500] = {0 }, num2 [1500] = {0}; char c; int num = 0; for (I = 0; I <l1; I ++) {if (I = 0) {c = str1 [I]; string1 [k] = c; if (str1 [I + 1] = '[') {for (j = I + 2 ;; j ++) if (str1 [j] = ']') break; int ans = change (I + 2, J-1); num1 [k] + = ans ;} else num1 [k] ++;} else {if (str1 [I] = c) {if (str1 [I + 1] = '[') {for (j = I + 2; j ++) if (str1 [j] = ']') break; int ans = change (I + 2, J-1 ); num1 [k] + = ans;} else num1 [k] + +;} Else if (str1 [I]! = C & str1 [I]> = 'A' & str1 [I] <= 'Z') {k ++; c = str1 [I]; string1 [k] = c; if (str1 [I + 1] = '[') {for (j = I + 1; j ++) if (str1 [j] = ']') break; int ans = change (I + 2, J-1); num1 [k] = ans ;} else num1 [k] ++ ;}} string1 [k + 1] = '\ 0';/* printf ("% d \ n", len1 ); for (I = 0; I <= k; I ++) {printf ("% c % d \ n", string1 [I], num1 [I]);} */int len1 = k + 1; // change str2; (that is, string B) k = 0; for (I = 0; I <l2; I ++) {char temp = str2 [I]; int num = 1; while (str2 [I] = str2 [I + 1]) {num ++; I ++ ;} num2 [k] = Num; string2 [k] = temp; k ++;} string2 [k] = '\ 0'; int len2 = k; // represents several characters in string2; // next we will judge; // printf ("% d \ n", len1, len2); k = 0; int p, q, flag = 1; for (I = 0; I <len1; I ++) {flag = 1; if (string1 [I] = string2 [k]) {// len2 = 1; if (len2 = 1) {if (num1 [I]> = num2 [k]) {flag = 1; puts ("True"); break ;} else {flag = 0; continue;} else if (len2> 1) {for (p = k + 1, q = I + 1; p <= len2-2; p ++, q ++) {if (string1 [q]! = String2 [p]) | (string1 [q] = string2 [p] & num1 [q]! = Num2 [p]) {flag = 0; break;} // printf ("% d \ n", flag );} // printf ("% d \ n", p, q); if (flag) {if (string1 [I] = string2 [k] & num1 [I]> = num2 [k]) & (string1 [q] = string2 [p] & num1 [q]> = num2 [p]) {flag = 1; puts ("True "); break;} else flag = 0;} if (flag) break; if (! Flag) {continue ;}}if (I = len1) puts ("False");} return 0 ;}

At first, I wanted to copy other people's code. Later I was told by senior students to do it by myself, so I was able to do it by myself. Only in this way can I continue to improve, come on!

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.