| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14802 | Adding positive integers |
|
| 14803 | Subdomain determination count |
|
| 14804 | Simulated bookshelf management system |
|
Description
Write a program to add two positive integers, each containing up to n digits.
Note that you cannot use int to store these integers, since an int only occupies four bytes and can represent numbers with up to 10 digits.
The program must store the two large integers as strings and perform the addition operation manually.
Due to the digit limitation, the addition can be easily handled using an appropriate data type.
Parameter specification: 0 < n ≤ 18
Input
Two positive integer.
Ex.123456789012345678
987654321098765432
Output
The sum of the integers.
Ex.1111111110111111110
Sample Input Download
Sample Output Download
Discuss
Description
An IP address consists of 32 bits. For convenience, it is usually written as four bytes, such as 192.168.61.82.
To determine whether two IP addresses belong to the same subnet, a subnet mask is used.
A subnet mask is an IP address where the higher bits are set to 1 and the lower bits are set to 0.
For example, if the first 26 bits are 1 and the remaining 6 bits are 0, the subnet mask is 255.255.255.192.
When two IP addresses are each ANDed with the subnet mask, the result extracts a certain number of higher bits — these bits represent the subnet identifier.
If two addresses have the same identifier, they belong to the same subnet.
Task:
Given a subnet mask, determine whether two IP addresses belong to the same subnet.
Constraints:
If any part of an IP address is N, then 0 ≤ N < 255.
Input
Input:
-
The first line contains four integers representing the subnet mask.
-
The second line contains IP address A.
-
Starting from the third line, there are multiple IP addresses to be checked.
Ex. 255 255 255 0
140 112 28 28
192 169 254 23
140 112 28 8
140 113 28 24
192 168 20 1
234 234 9 34
192 168 20 45
140 112 29 2
140 112 28 88
Output
Output:
Print the number of IP addresses that are in the same subnet as A.
The program must process all input until EOF.
Ex. 2
Sample Input Download
Sample Output Download
Discuss
Description
Write a program to simulate a bookshelf system.
Assume you have 255 books and a bookshelf that can hold up to 8 books.
Each book is numbered from 1 to 255, and initially, all books are on the desk (i.e., the bookshelf is empty).
When you want to read a book:
-
If the book is already on the bookshelf, take it out and read it, then place it on the rightmost side of the bookshelf.
-
If the book is not on the bookshelf, take it from the desk and also place it on the rightmost side of the bookshelf.
If the bookshelf is already full (8 books) when adding a new one, the leftmost book (the one that has stayed the longest) is removed from the bookshelf, and the new book is placed at the rightmost position.
Your task is to simulate this process and output the final state of the bookshelf after a sequence of reading operations.
Input
A sequence of integers between 1 and 255, representing the order in which books are read.
The program should process all inputs until EOF.
Ex.1 2 3 4 5 6 7 8 6 10 23 7 4
Output
8 integers, representing the final state of the bookshelf from left to right.
If a position on the bookshelf is empty, output 0 for that position.
Ex. 3 5 8 6 10 23 7 4