Add files via upload

This commit is contained in:
Dom Sec 2023-03-23 21:48:17 -04:00 committed by GitHub
parent 1720b662e4
commit 1cbd24d394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 592 additions and 0 deletions

View File

@ -0,0 +1,32 @@
## TCP/IP Client and Server
At the very high level, there are two actors: a client and a server.
The server has a know IP address that represents a machine to connect to at some point (this address could be retrieved via DNS) and a known port (that represents the service that we want to talk to in that machine).
At this moment, nothing can happen - TCP has its communication based on connections and without some handshaking and connection establishment, no data can be sent. Once the connection gets established, its then up to the application to decide whether theres indeed a server component and a client component. They could be peers and synchronize data back and forth, for instance.
For an application protocol like HTTP/1.1 though, theres a well-defined client-server model, where a client issues requests with specific methods, and a server that processes these requests and gives back results.
### Echo Server
Create a TCP server that receives incoming messages and echos them back to the sender. It should start by creating a TCP/IP socket connection.
- In the TCP Echo server , we create a socket and bind to a parameterized port number.
- After binding , the process listens for incoming connections.
- Then an infinite loop is started to process the client requests for connections.
- After a connection is requested , it accepts the connection from the client machine and forks a new process.
- The new process receives data from the client and echoes the same data back.
- Please note that this server is capable of handling multiple clients as it forks a new process for every client trying to connect to the server.
### Echo Client
The client program sets up its socket differently from the way a server does. Instead of binding to a port and listening, it uses connect() to attach the socket directly to the remote address.
- In the TCP Echo client a socket is created.
- Using the socket a connection is made to the server.
- After a connection is established , we send messages input from the user and display the data received from the server
### Client and Server Together
The client and server should be run in separate terminal windows, so they can communicate with each other.

View File

@ -0,0 +1,27 @@
## Way Too Long Words
Sometimes some words like "**localization**" or "**internationalization**" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is **strictly more than 10 characters**. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "**localization**" will be spelt as "**l10n**", and "**internationalization**" will be spelt as "**i18n**".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
### Input
```
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
```
### Output
```
word
l10n
i18n
p43s
```

View File

@ -0,0 +1,23 @@
## Hulk
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the _Inception_ so much, and like that his feelings are complicated. They have **n** layers. The first layer is hate, second one is love, third one is hate and so on...
For example if **n=1**, then his feeling is **"I hate it"** or if **n=2** it's **"I hate that I love it"**, and if **n=3** it's **"I hate that I love that I hate it"** and so on.
Please help Dr. Banner.
### Input
```
1
2
3
```
### Output
```
I hate it
I hate that I love it
I hate that I love that I hate it
```

View File

@ -0,0 +1,27 @@
## Hit the Lottery
Allen has a LOT of money. He has 𝑛 dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are **1**, **5**, **10**, **20**, **100**.
What is the minimum number of bills Allen could receive after withdrawing his entire balance?
### Input
```
125
43
1000000000
```
### Output
```
3
5
10000000
```
### Note
In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills.
In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills.
In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills.

View File

@ -0,0 +1,27 @@
## Minutes Before the New Year
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows **** hours and **𝑚** minutes, where **0≤<24** and **0≤𝑚𝑚<60**.
We use 24-hour time format!
Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows 0
hours and 0 minutes.
### Input
```
23 55
23 0
0 1
4 20
23 59
```
### Output
```
5
60
1439
1180
1
```

View File

@ -0,0 +1,63 @@
## Radio Station
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has **n** servers.
Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server.
For simplicity, we'll assume that an **nginx** command is of form "**command ip;**" where **command** is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
<p align="center">
<img src="../../../assets/Dustin.png" alt="OMG">
</p>
Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
### Input
The first line of input contains two integers n and m (1n,m1000).
The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1|name|10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1|command|10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers.
```
2 2
main 192.168.0.2
replica 192.168.0.1
block 192.168.0.1;
proxy 192.168.0.2;
```
### Output
Print m lines, the commands in the configuration file after Dustin did his task.
```
block 192.168.0.1; #replica
proxy 192.168.0.2; #main
```
### Input
```
3 5
google 8.8.8.8
codeforces 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57;
block 8.8.8.8;
cf 212.193.33.27;
unblock 8.8.8.8;
check 138.197.64.57;
```
### Output
```
redirect 138.197.64.57; #server
block 8.8.8.8; #google
cf 212.193.33.27; #codeforces
unblock 8.8.8.8; #google
check 138.197.64.57; #server
```

View File

@ -0,0 +1,32 @@
## Cyberpunk 2078
Today Vasya visited a widely known site and learned that the continuation of his favourite game **Cyberpunk 2077** will appear after exactly k months. He looked at the calendar and learned that at the moment is the month number s. Vasya immediately got interested in what month **Cyberpunk 2078** will appear. Help him understand that.
All the twelve months in Vasya's calendar are named using their usual English names: **January, February, March, April, May, June, July, August, September, October, November, December**.
### Input
The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer k (0k100) — the number of months left till the appearance of **Cyberpunk 2078**.
```
November
3
```
### Output
Print starting from an uppercase letter the name of the month in which the continuation of **Cyberpunk 2077** will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.
```
February
```
### Input
```
May
24
```
### Output
```
May
```

View File

@ -0,0 +1,33 @@
## New Year Candles
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles. When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
### Input
The single line contains two integers, a and b (1a1000; 2b1000).
```
4 2
```
### Output
Print a single integer — the number of hours Vasily can light up the room for.
```
7
```
### Input
```
6 3
```
### Output
```
8
```
### Note
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

View File

@ -0,0 +1,44 @@
## Dreamoon and Stairs
Dreamoon wants to climb up a stair of **n** steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer **m**.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
### Input
The single line contains two space separated integers **n**, **m** (0<n10000,1<m10).
```
10 2
```
### Output
Print a single integer — the minimal number of moves being a multiple of **m**. If there is no way he can climb satisfying condition print **-1** instead.
```
6
```
### Input
```
3 5
```
### Output
```
-1
```
### Note
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
### More examples of Input & Output
```
climbMoves(13, 2) == 8 //2 2 2 2 2 1 1 1
climbMoves(6, 4) == 4 //2 2 1 1
climbMoves(7, 4) == 4 //2 2 2 1
climbMoves(8, 4) == 4 //2 2 2 2
climbMoves(9, 4) == 8 //2 1 1 1 1 1 1 1
climbMoves(5, 3) == 3 //2 2 1
climbMoves(6, 3) == 3 //2 2 2
climbMoves(7, 3) == 6 //2 1 1 1 1 1
```

View File

@ -0,0 +1,56 @@
## Superhero Transformation
We all know that a superhero can transform to certain other superheroes. But not all superheroes can transform to any other superhero. A superhero with name 𝑠 can transform to another superhero with name 𝑡 if 𝑠 can be made equal to 𝑡 by changing any vowel in 𝑠 to any other vowel and any consonant in 𝑠 to any other consonant. Multiple changes can be made.
**In this problem**, we consider the letters 'a', 'e', 'i', 'o' and 'u' to be vowels and all the other letters to be consonants.
Given the names of two superheroes, determine if the superhero with name 𝑠
can be transformed to the Superhero with name 𝑡.
### Input
The first line contains the string 𝑠 having length between 1 and 1000, inclusive.
The second line contains the string 𝑡 having length between 1 and 1000, inclusive.
Both strings 𝑠 and 𝑡 are guaranteed to be different and consist of lowercase English letters only.
```
a
u
```
### Output
Output "Yes" (without quotes) if the superhero with name 𝑠 can be transformed to the superhero with name 𝑡 and "No" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
```
Yes
```
### Input
```
abc
ukm
```
### Output
```
Yes
```
### Input
```
akm
ua
```
### Output
```
No
```
### Notes
In the first sample, since both 'a' and 'u' are vowels, it is possible to convert string 𝑠 to 𝑡.
In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string 𝑠 to 𝑡.

View File

@ -0,0 +1,47 @@
## Free Cash
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
### Input
The first line contains a single integer n (1n105), that is the number of cafe visitors.
Each of the following n lines has two space-separated integers hi and mi (0hi23; 0mi59), representing the time when the i-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
```
4
8 0
8 10
8 10
8 45
```
### Output
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
```
2
```
### Input
```
3
0 12
10 11
22 22
```
### Output
```
1
```
### Notes
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash.

View File

@ -0,0 +1,37 @@
## Beautiful Paintings
There are **n** pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1in-1), such that ai+1>ai.
### Input
The first line of the input contains integer n (1n1000) — the number of painting.
The second line contains the sequence a1,a2,...,an (1ai1000), where ai means the beauty of the i-th painting.
```
5
20 30 10 50 40
```
### Output
Print one integer — the maximum possible number of neighbouring pairs, such that ai+1>ai, after the optimal rearrangement.
```
4
```
### Input
```
4
200 100 100 200
```
### Output
```
2
```
### Notes
In the first sample, the optimal order is: 10,20,30,40,50.
In the second sample, the optimal order is: 100,200,100,200.

View File

@ -0,0 +1,35 @@
## Elephant
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x>0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he needs to make in order to get to his friend's house.
### Input
The first line of the input contains an integer x (1x1000000) — The coordinate of the friend's house.
### Output
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
### Input Example
```
5
```
### Output Example
```
1
```
### Input Example
```
12
```
### Output Example
```
3
```
### Notes
In the first sample the elephant needs to make one step of length 5 to reach the point x.
In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.

View File

@ -0,0 +1,58 @@
## Geography of Brazil
Today's theme is the Geography of BRAZIL, a very large country.
Currently, the country is divided into 26 states and the Federal District, altogether there are 27 federative units.
Brazil has gone through several regionalizations, which have changed the configuration of the Brazilian territory over the years. The current regionalization is related to the Federal Constitution of 1988, in which some states arose and other territories were elevated to the category of state.
What few people actually know is the number of Municipalities per State. Create a function that obtains this information!
### Input & Example
The only input parameter is the state's acronym.
```
SP
```
### Output & Example
The output is the number of municipalities in the state informed.
```
645
```
### Brazilian states and acronyms
|||
|--- |--- |
|State|Acronym|
|Acre|AC|
|Alagoas|AL|
|Amapá|AP|
|Amazonas|AM|
|Bahia|BA|
|Ceará|CE|
|Espírito Santo|ES|
|Goiás|GO|
|Maranhão|MA|
|Mato Grosso|MT|
|Mato Grosso do Sul|MS|
|Minas Gerais|MG|
|Pará|PA|
|Paraíba|PB|
|Paraná|PR|
|Pernambuco|PE|
|Piauí|PI|
|Rio de Janeiro|RJ|
|Rio Grande do Norte|RN|
|Rio Grande do Sul|RS|
|Rondônia|RO|
|Roraima|RR|
|Santa Catarina|SC|
|São Paulo|SP|
|Sergipe|SE|
|Tocantins|TO|
|Distrito Federal|DF|
### Notes:
You can make use of the public [API](https://servicodados.ibge.gov.br/api/v1/localidades/municipios) of the Brazilian Institute of Geography and Statistics (IBGE).

View File

@ -0,0 +1,15 @@
## Final Hello World
Your boss asks you to write a **"hello world"** program. Since you get paid for lines of code, you want to make it as complex as possible. However if you just add nonsense lines, or obviously useless or obfuscating stuff, you will never get it through code review. Therefore the challenge is:
Write a **"hello world"** program which is as complex as possible under the condition that you can give a "_justification_" for every complexity in the code.
The required behavior of the program is to just output a single line "Hello world" (without the quotes, but with a newline at the end) and then exit successfully.
"Justifications" include:
- buzzword compatibility ("Modern software is object oriented!")
- generally accepted good programming practices ("Everyone knows that you should separate model and view")
- maintainability ("If we do it this way, we can more easily do XXX later")
- and of course any other justification you can imagine using (in other situations) for real code.

View File

@ -0,0 +1,36 @@
## How is the Weather?
You intend to visit **Brazil** and get to know its main tourist spots on your well-deserved vacation.
To make the most of this period, from the list of municipalities in your travel itinerary, you would like to know the weather conditions for the next 5 days (including the current day) of each municipality informed.
Write a function that displays the weather forecast for a municipality informed for the next 5 days (including the current day).
### Input parameters:
- Name of the municipality (it can be a partial name, the system must do a best guess)
- State abbreviation (all uppercase, 2 characters long)
## Output:
Object with the following structure:
- Name of the municipality
- State abbreviation
- List/Vector/Array containing 5 forecasts (one for each day, including today). Each forecast has:
- Morning:
- Minimum Temperature (° C)
- Maximum Temperature (° C)
- Resume
- Afternoon:
- Minimum Temperature (° C)
- Maximum Temperature (° C)
- Resume
- Evening:
- Minimum Temperature (° C)
- Maximum Temperature (° C)
- Resume
### Notes:
- You can make use of the public [API](https://servicodados.ibge.gov.br/api/v1/localidades/municipios) of the Brazilian Institute of Geography and Statistics (IBGE) to get more information about municipalities and states. This API was used on [day-98 challenge](../../Week-14/day-98/README.md).
- You can make use of the public [weather forecast API](https://portal.inmet.gov.br/manual/manual-de-uso-da-api-de-previs%C3%A3o) of the Brazilian Institute of Geography and Statistics (IBGE).
- If the forecast is not available in all three times of the day, use a single forecast for the whole day. This is specially common for days after day 3.