Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

ACM Pacific NW Region Programming Contest Problem B: Zipper, Study notes of Algorithms and Programming

The details of problem b in the acm pacific nw region programming contest held on november 13, 2004. The problem involves determining if the third string can be formed by combining the characters in the first two strings while maintaining their original order. The input consists of multiple data sets, each with three strings, and the output is a 'yes' or 'no' indicating whether the third string can be formed from the first two.

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-jyp
koofers-user-jyp 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ACM Pacific NW Region Programming Contest
13 November 2004
Page 1 of 2
Problem B
Zipper
Problem description
Given three strings, you are to determine whether the third string can be formed by
combining the characters in the first two strings. The first two strings can be mixed
arbitrarily, but each must stay in its original order.
For example, consider forming "tcraete" from "cat" and "tree":
String A: cat
String B: tree
String C: tcraete
As you can see, we can form the third string by alternating characters from the two
strings. As a second example, consider forming "catrtee" from "cat" and "tree":
String A: cat
String B: tree
String C: catrtee
Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".
The Input (from file b.in)
The first line of input file, b.in, contains a single positive integer from 1 through
1000. It represents the number of data sets to follow. The processing for each data set
is identical. The data sets appear on the following lines, one data set per line.
For each data set, the line of input consists of three strings, separated by a single
space. All strings are composed of upper and lower case letters only. The length of the
third string is always the sum of the lengths of the first two strings. The first two strings
will have lengths between 1 and 200 characters, inclusive.
The Output (to stdout)
For each data set, print:
Data set n: yes
if the third string can be formed from the first two, or
Data set n: no
if it cannot. Of course n should be replaced by the data set number. See the sample
output below for an example.
pf2

Partial preview of the text

Download ACM Pacific NW Region Programming Contest Problem B: Zipper and more Study notes Algorithms and Programming in PDF only on Docsity!

ACM Pacific NW Region Programming Contest

13 November 2004

Page 1 of 2

Problem B

Zipper

Problem description

Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.

For example, consider forming "tcraete" from "cat" and "tree":

String A: cat String B: tree String C: tcraete

As you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":

String A: cat String B: tree String C: catrtee

Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".

The Input (from file b.in) The first line of input file, b.in, contains a single positive integer from 1 through

  1. It represents the number of data sets to follow. The processing for each data set is identical. The data sets appear on the following lines, one data set per line.

For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two strings will have lengths between 1 and 200 characters, inclusive.

The Output (to stdout) For each data set, print:

Data set n: yes

if the third string can be formed from the first two, or

Data set n: no

if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example.

ACM Pacific NW Region Programming Contest

13 November 2004

Page 2 of 2

Sample input

3 cat tree tcraete cat tree catrtee cat tree cttaree

Sample output

Data set 1: yes Data set 2: yes Data set 3: no