80 байт....
Aug. 25th, 2005 07:26 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
На http://spoj.sphere.pl много интересных задач, хочу поделиться одной.
53. KAMIL
Условие:
Some kids cannot pronounce all letters, some of them they sometimes pronounce correctly and sometimes incorrectly. Kamil sometimes says T instead of K, but he never says K instead of T. Similarly he sometimes says D instead of G. Instead of R he sometimes says L and sometimes F. Of course it happens that he pronounces the letter correctly. Kamil's father always thinks how many words can mean the word spoken by his son (it doesn't matter if they are real English words).
Task
Write a program which
* reads from standard input the words spoken by Kamil
* counts how many different words can that mean
* writes the outcome on standard output
Input
Ten test cases (given one under another, you have to process all!). Every test case is a single line - a word spoken by Kamil. Only 26 capital leters are used. The length of the word is at most 20.
Output
For every testcase write an integer in a single line with a single integer, denoting the number of words which Kamil's word can mean.
То есть, для заданной последовательности букв, необходимо определить, сколько вариантов различных слов может за ней скрываться. Читает прога со стандартного входа (stdin), пишет в стандартный выход (stdout). Вводимые данные - только заглавные латинские буквы 'A'-'Z' не более 20 символов для каждого слова. Всего на вход даются 10 строк.
Ограничение для этой задачи - размер исходника. Не более 256 байт. Чем меньше, тем лучше.
Для языка C (при проверке организаторами используется gcc 4.0.0-8) размер мого решения 133 байта. Как уменьшить не знаю, но точно знаю, что можно, т.к. среди решивших эту задачу в топах для сишников висит решение в 80 (восемьдесят) байт.
Никто не хочет поломать голову? :)
мое решение:
Если убрать пробелы, табуляции и склеить все в одну строку, то получм 133 байта.
Но можно меньше.
Блин... как? :)
53. KAMIL
Условие:
Some kids cannot pronounce all letters, some of them they sometimes pronounce correctly and sometimes incorrectly. Kamil sometimes says T instead of K, but he never says K instead of T. Similarly he sometimes says D instead of G. Instead of R he sometimes says L and sometimes F. Of course it happens that he pronounces the letter correctly. Kamil's father always thinks how many words can mean the word spoken by his son (it doesn't matter if they are real English words).
Task
Write a program which
* reads from standard input the words spoken by Kamil
* counts how many different words can that mean
* writes the outcome on standard output
Input
Ten test cases (given one under another, you have to process all!). Every test case is a single line - a word spoken by Kamil. Only 26 capital leters are used. The length of the word is at most 20.
Output
For every testcase write an integer in a single line with a single integer, denoting the number of words which Kamil's word can mean.
То есть, для заданной последовательности букв, необходимо определить, сколько вариантов различных слов может за ней скрываться. Читает прога со стандартного входа (stdin), пишет в стандартный выход (stdout). Вводимые данные - только заглавные латинские буквы 'A'-'Z' не более 20 символов для каждого слова. Всего на вход даются 10 строк.
Ограничение для этой задачи - размер исходника. Не более 256 байт. Чем меньше, тем лучше.
Для языка C (при проверке организаторами используется gcc 4.0.0-8) размер мого решения 133 байта. Как уменьшить не знаю, но точно знаю, что можно, т.к. среди решивших эту задачу в топах для сишников висит решение в 80 (восемьдесят) байт.
Никто не хочет поломать голову? :)
мое решение:
main() { char s[21],*p; int k=10,n; while(k--) { scanf("%20s",s); p=s; n=1; while(*p) n*=(strchr("TDLF",*p++)?2:1); printf("%d\n",n); } return 0; }
Если убрать пробелы, табуляции и склеить все в одну строку, то получм 133 байта.
Но можно меньше.
Блин... как? :)