Problem description | | Progress |
Темы:
Symbols
Conditional operator
Whole numbers
In the elections to the State Duma, N parties were included in the ballots. An electronic scanner for reading information from ballots transmits information about each ballot in the following format: if there is a mark in the corresponding box of the ballot, then the scanner transmits + (plus), otherwise it transmits - (minus). Thus, it sends a sequence of N characters - pluses and minuses.
The ballot is considered valid if the mark is in exactly one cell. Invalid ballots are not included in the calculation of election results.
A party enters the State Duma only if it receives at least 7% of the total number of valid ballots.
It is required to display the numbers (in the order they are listed in the ballot) of all parties that are going to the State Duma.
Input
The first line of the input contains two numbers separated by a space: N - the number of parties and M - the number of ballots. Both numbers are natural, N ≤ 200, M≤ 100 000.
The next M lines contain the information obtained from the ballots. Each line is a sequence of N characters + or - (no spaces).
It is guaranteed that there is at least one valid ballot.
Imprint
Output the numbers of the parties that entered the Duma, separated by a space, in ascending order. If none of the parties makes it to the Duma, nothing needs to be displayed.
Examples
# |
Input |
Output |
1 |
3 4
+--
+--
-+-
+-+ |
1 2 |
2 |
1 5
+
-
-
-
- |
1 |
| |
|
Темы:
Symbols
Simulation tasks
"Draw" using the characters on the forest screen. In this case, do not use commands to move the cursor around the screen. Your program must print the characters of the lines (or the entire line) sequentially.
Forest — it is one or more Christmas trees. Each Christmas tree is characterized by the number of triangles in it and the size of the smallest triangle. The herringbone consists of triangles whose vertices are strictly under each other, and each next triangle contains one line more than the previous one.
All Christmas trees should start vertically from the first line. Each Christmas tree should be located as far to the left as possible, while the Christmas trees should not touch (i.e. there should not be symbols depicting another Christmas tree near the symbols of the Christmas tree on the right, left, bottom, top, and also diagonally) and the order should not be violated Christmas trees.
Christmas trees should be depicted with the symbols «#» (lattice), and the empty spaces between them — symbols «.» (dot). All lines must display the same number of characters, and there must be a line in which the last character is a pound sign, the last line must contain hacks (i.e., a rectangle of dots and bars should be displayed, it should not contain extra columns and rows).
Input
The number of Christmas trees is entered N, and then N pairs of natural numbers describing the Christmas trees: the first number of each pair specifies the number of triangles in the Christmas tree, and the second — the size of the smallest triangle. The Christmas trees are described in order from left to right (if you look at the tops of the Christmas trees).
It is guaranteed that the input data will be such that the number of characters to be output in one line will not exceed 79.
Imprint
Output the required "drawing". See examples for better understanding.
Examples
# |
Input |
Output |
1 |
2
3 2
3 3
|
...#......#....
..###....###...
...#....#####..
..###.....#....
.#####...###...
...#....#####..
..###..#######.
.#####....#....
#######..###...
........#####..
......#######.
......#########
|
2 |
3
1 1
2 1
3 2 |
#.#...#...
..#..###..
.###..#...
.....###..
....#####.
......#...
.....###..
....#####.
...#######
|
| |
|
Темы:
Symbols
Misha is preparing for the exam in computer science. He is currently studying problem A4, which describes how to work with file masks:
For batch operations with files, file name masks are used. The mask is a sequence of letters, numbers, and other characters allowed in file names, which may also contain the following characters.
The symbol "?" (question mark) means exactly one arbitrary character.
The symbol "*" (asterisk) means any sequence of characters of arbitrary length, including "*" can also specify an empty sequence.
Since there is no open bank of tasks for the Unified State Exam in computer science, Misha has to train on his own. Write a program that will determine for each file name whether it matches the given mask so that Misha can check his answers. It is guaranteed that no more than one "*" character is present in the file mask.
Input
The first line contains the file mask. The next 5 lines contain the file names, one per line. File names consist of small Latin letters, numbers and the "." symbol. (dot), the mask can also contain the characters «?» and "*" (symbol "*" — no more than once). The length of each line does not exceed 20 characters.
Imprint
For each filename print the word "YES" if it satisfies the mask and "NO" otherwise. Words should be displayed in capital Latin letters without quotes, each in a new line.
Examples
# |
Input |
Output |
1 |
?or*.d??
fort.doc
ford.doc
lord2.doc
orsk.dat
port |
YES
YES
YES
NO
NO |
| |
|
Темы:
Symbols
Write a program that converts the given character to uppercase.
Input
Single character c.
Imprint
If the character is a lowercase letter of the Latin alphabet (that is, a letter from a to z), print the same capital letter instead, otherwise print the same character (this operation is called "uppercase").
Examples
# |
Input |
Output |
1 |
e |
E |
2 |
B |
B |
| |
|
Темы:
Strings
Symbols
Given a line. It is known that it contains exactly two identical letters. Find these letters. It is guaranteed that only one type of letter is repeated.
Input
The input is 1 line.
Imprint
You need to print a letter that occurs twice in a string.
Examples
| |
|
Темы:
Conditional operator
Strings
Symbols
There is always an integer in Gromozeka's mind. Initially, in Gromozeka's mind, the integer is 0 . Now Gromozeka is going to eat four cookies, each of which has either + or - written on it. When he eats a cookie with the symbol + , the integer in his mind increases by 1 ; when he eats a cookie with a - character, the integer in his mind decreases by 1 . The cookies that Gromozeka is about to eat are given to you as a string S, i th character in S is i is the cookie he eats. Find the integer in Gromozeka's mind after he has eaten all the cookies.
Input
The input is a string of 4 characters, each of which is equal to + or - .
Imprint
Print an integer in Gromozeka's mind after he has eaten all the cookies.
Examples
# |
Input |
Output |
1 |
+-++
|
2 |
2 |
-+--
|
-2 |
3 |
----
|
-4 |
| |
|
Темы:
Symbols
Strings
The input of the program is the string s. Using character references by index and string slices, print the following substrings:
- all characters from index 3 to the middle of the string inclusive (if the length of the string is odd, do not take the middle character);
- last character;
- all characters with even indexes (0, 2, ...);
- all characters with odd indices (1, 3, ...);
- all characters except the last one;
- all characters except the first one;
- all characters in reverse order;
- all characters in reverse order, starting with 3 from the end, and except for the first two;
- all characters of the first half in reverse order, except for the first (if the length of the line is odd, do not take the middle character);
- slicing copy the entire string s to the string
s2 .
Add lines to the program.
Examples
# |
Input |
Output |
1 |
Hallo, World! |
lo,
!
Hlo ol!
al,Wrd
Hallo, World
Hello, World!
!dlroW ,ollaH
lroW ,oll
,olla
Hallo, World! |
| |
|
Темы:
Tasks for procedures and functions
Strings
Symbols
Write a vowels_count function that takes a string and counts the number of English vowels in it.
English vowels: a, e, i, o, u, y .
Using this function, define two lines:
s1 - the string with the largest number of vowels (if there are several such strings, take the one that occurs first).
s2 - the string with the smallest number of consonants (if there are several such strings, take the one that occurs first).
Input
The first line contains a natural number n (1 < n <= 10) - the number of lines. Next come n lines. Each line consists of small English letters and spaces.
Imprint
Print two lines on the screen: first, the line s1 , then, on a new line, s2 . Align the smallest of these strings with the largest one by adding the characters '* '.
Examples
# |
Input |
Output |
1 |
4
mama papa
doughter son
brother sister
grandmama grandpa |
grandmama grandpa
********mama papa |
| |
|
Темы:
Strings
Symbols
You are given a string S exactly 9 characters long. Each character in the string is any of the digits from 0 to 9 . All characters in the string are different. Print the missing digit in the string.
Input
The input is a string consisting of numbers.
Imprint
Display the answer to the problem
Examples
# |
Input |
Output |
1 |
023456789
|
1
|
2 |
459230781
|
6
|
| |
|
Темы:
Strings
Symbols
An offer has been given. Print all its characters preceding the first comma. If there are no commas in the sentence, then output the entire sentence.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is the original sentence.
Output: you need to print all the characters of the sentence that precede the first comma, if there are no commas, print the entire sentence
Input and output example
Test number |
Input |
Output |
1 |
fore, s t.
|
fore |
2 |
fore s t. |
fore s t. |
| |
|
Темы:
Strings
Symbols
Given a sentence that contains several letters 'e' (English). Find the serial number of the first one.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is the original sentence.
Output: you need to output the number of the first letter "e" (eng) in a sentence
Input and output example
Test number |
Input |
Output |
1 |
foresete |
4 |
| |
|
Темы:
Symbols
Strings
An offer has been given. Determine if it contains the letter " a " (English). If the answer is yes, output the serial number of the first of them. If it is negative, output the word NO .
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is the original sentence.
Output: print the answer to the problem.
Input and output example
Test number |
Input |
Output |
1 |
foresete |
NO |
2 |
forast |
4 |
| |
|
Темы:
Strings
Symbols
The word is given. Check if it is a "changeling", (that is, it is read the same way both from the beginning and from the end).
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is a word.
Output: need to output the word "YES " if the word is a shifter, and the word "NO code>" - otherwise
Sample input and output
Test number |
Input |
Output |
1 |
foresete |
NO |
2 |
halah |
YES |
| |
|
Темы:
Strings
Symbols
Given a string divided into sentences. All sentences end with a dot. Determine the number of letters 'i' in the first sentence.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The program receives a string as input.
Output: need to print the number of letters 'i' in the first sentence.
Sample input and output
Test number |
Input |
Output |
1 |
foresete. forest. |
0 |
2 |
firist. forest |
2 |
| |
|
Темы:
Symbols
Strings
Two words are given. Determine how many initial letters of the first word match the initial letters of the second word
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: the first line contains two words separated by a space
Output: need to print the number of letters matching from the beginning
Sample input and output
Test number |
Input |
Output |
1 |
fore forest |
4 |
2 |
forest torest |
0 |
| |
|
Темы:
Strings
Symbols
A sentence is given that does not contain the "-" symbol. Determine the number of letters "o" (English) in the first word. There may be spaces at the beginning of a sentence.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: a single line specifies the original sentence.
Output: need to print the number of letters "o" (English) in the first word.
Sample input and output
Test number |
Input |
Output |
1 |
fore sete. |
1 |
2 |
halah. |
0 |
| |
|
Темы:
Symbols
Strings
An offer has been given. Count the number of "n" letters preceding the first comma of the sentence.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is the original sentence.
Output:
Sample input and output
Test number |
Input |
Output |
1 |
fore, sete. |
0 |
2 |
hanah. |
1 |
| |
|
Темы:
Strings
Symbols
An offer has been given. Determine the serial numbers of the first pair of identical neighboring characters. If there are no such characters, then display the word NO.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is a sentence.
Output: you need to output serial numbers of the first pair of identical adjacent characters separated by a space, or the word "NO" - if there is no such pair of adjacent characters
Sample input and output
Test number |
Input |
Output |
1 |
foresete |
NO |
2 |
haah |
2 3 |
| |
|
Темы:
Symbols
Strings
Given a sequence of characters, at the beginning of which there is a certain number of identical characters. Determine this quantity.
Solve the problem without using the built-in string functions, except for a function that returns the length of a string.
Input: The first line is a sequence of characters.
Output: should print the number of identical characters at the beginning of the string.
Sample input and output
Test number |
Input |
Output |
1 |
foresete |
0 |
2 |
aaav |
3 |
| |
|
Темы:
Symbols
Strings
Change the case of the character. If it was a lowercase English letter, make it a capital letter; if it was a capital English letter - lowercase.
Input
Single character c .
Imprint
You need to output the resulting character.
Examples
# |
Input |
Output |
1 |
a |
A |
2 |
B |
b |
| |
|
Темы:
Symbols
Strings
A character and a sentence are written in one line separated by a space. Write a program that counts how many words in a sentence that end in a given character. There is only one space between words in the sentence, there are no spaces at the end and at the beginning.
Sample input and output
Test number |
Input |
Output |
1 |
a b |
0 |
2 |
t test word |
1 |
| |
|
Темы:
Symbols
Strings
Given a line. Write a program that determines if a given string contains digits.
Sample input and output
Test number |
Input |
Output |
1 |
test |
NO |
2 |
Ocenka-5 |
YES |
| |
|
Темы:
Symbols
Strings
A number and some text are written in one line separated by a space. Write a program that outputs from the text those characters whose numbers are multiples of a given number (numbering starts from 1).
Sample input and output
Test number |
Input |
Output |
1 |
2 words |
lv |
2 |
3 test test |
stt |
| |
|
Темы:
Symbols
Strings
One line contains a character and some text. Write a program that replaces all even-numbered characters in text with a given character. Character numbering starts from 1.
Sample input and output
Test number |
Input |
Output |
1 |
t word |
stoto |
2 |
a test test |
tasa aeat |
| |
|
Темы:
Symbols
Strings
One line contains two characters and some text separated by a space. Write a program to replace all letters in the text that match the first character with the second.
Sample input and output
Test number |
Input |
Output |
1 |
a b slovo |
slovo |
2 |
r t rr rr |
tt tt |
| |
|
Темы:
Strings
Symbols
The line is written as a sentence. Write a program that will determine the number of words in it. There is only one space between words in the sentence, there are no spaces at the end and at the beginning.
Sample input and output
Test number |
Input |
Output |
1 |
test |
1 |
2 |
test test |
2 |
| |
|