Sunday, March 9, 2014

COCI 2013./2014. - Round #6 Task VJEKO solution

CROATIAN OPEN COMPETITION IN INFORMATICS

all tasks editorial: http://codeforces.com/blog/entry/10747

COCI 2013./2014. - Round #6 Task VJEKO: http://hsin.hr/coci/contest6_tasks.pdf

COCI 2013/2014 Task VJEKO
6
th round, March 8th, 2014 Author: Marin Tomić

In his spare time, Vjeko likes to browse through files in directories. Unfortunately, it seems to him that
the console on his computer broke down and now it doesn't correctly print file names that match a
certain pattern.
A pattern is string consisting of lowercase letters of the English alphabet and exactly one asterisk.
A file name matches a pattern if the pattern string can be made equal to the file name by replacing the
asterisk with an arbitrary string of lowercase letters of the English alphabet (an empty string
substitution is also possible). For example, strings “abcd”, “ad” and “anestonestod” all match the
pattern “a*d” and the string “bcd” does not.
Write a programme that will, given a pattern and file names, output whether a file name matches the
pattern or not.
INPUT
The first line of input contains the integer N (1 ≤ N ≤ 100), the number of files.
The second line of input contains a string of characters consisting of only lowercase letter of the
English alphabet and exactly one asterisk (ASCII value 42). The length of the string will not exceed 100
and the asterisk will not be located at the beginning nor at the end of the string.
Each of the following N lines contains file names, each in its own line. The file names consist of only
lowercase letters of the English alphabet and their length will not exceed 100.
OUTPUT
Output N lines. The i
th line should be “DA” (Croatian for yes) if the i
th file name matches the pattern
or “NE” (Croatian for no) if the i
th file name does not match the pattern.
SAMPLE TESTS
input

3
a*d
abcd
anestonestod
facebook




output

DA
DA
NE
input

6
h*n
huhovdjestvarnomozedocisvastan
honijezakon
atila
je
bio
hun

output

DA
DA
NE
NE
NE
DA


COCI 2013./2014. - Round #6 Task VJEKO solution: http://ideone.com/ik3UsR

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
int n;
char s[105], a[105], flag;
scanf("%d", &n);
scanf("%s", a);
while(n--) {
flag=0;
scanf("%s", s);
for(int i=0; a[i]!='*'; i++) {
if(s[i]!=a[i]) {
flag=1;
break;
}
}
for(int i=strlen(s)-1, j=strlen(a)-1; a[j]!='*'; i--, j--) {
if(s[i]!=a[j]) {
flag=1;
break;
}
}
if(flag) printf("NE\n");
else printf("DA\n");
}
return 0;
}

note: i got tired of checking whether the answer is true or not, so i just wrote other program which checks the answer if it is AC or not: http://ideone.com/BlZq91

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
int n, flag;
flag=0;
char a[105][5], b[105][5];
scanf("%d", &n);
for(int i=0; i<n; i++) scanf("%s", a[i]);
for(int i=0; i<n; i++) scanf("%s", b[i]);
for(int i=0; i<n; i++) {
if(a[i]!=b[i]) {
flag=1;
break;
}
}
if(flag) printf("AC\n");
else printf("WA\n");
return 0;
}

No comments:

Post a Comment