Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Lyubomir_92 avatar Lyubomir_92 0 Точки

Song Encryption

Здравейте , задачата ми минава 80/100

 Код: https://pastebin.com/MjUhmHuX

Условие:

Problem 02. Song Encryption

Now that you've helped Mandy to accept the group applications it's time to assist her with a security problem. You are tasked to encrypt all songs from the set list so that if someone steals it they won't be able to leak it online.

Your task is to write a program that encrypts information about artists and their songs.

Until you receive the command "end" you should read lines in following format :"{artist}:{song}", and check if it's valid, considering the following rules:

  • Artiststarts with capital letter, followed by lowercase letters.
    •  It can also contains apostrophe ( ' ), and whitespace " ";

Valid group name: Red hot chili peppers, Eminem, Guns n' roses

Invalid group name: ReD Hot CiLly PePers, sLipKnot, guns n'roses

  • Song – contains only capital letters, and whitespaces.

Valid songs: BACK IN BLACK, BLEED IT OUT, KILLSHOT

Invalid songs: #BaCk IN black, BLEED $IT$ OUTt, &KILLSHoT

After you validate the lines of an input, you should encrypt the information. In order to do that, you have to follow the rules below:

  • First you need to find a key for encryption.
    • Your key is the length of the artist (e.g. "Eminem" –  key: 6)
  • You have to increment the ASCII value of each symbol of the input, with the key length
    • e.g. "char" 'a' -> 'g')
  • Be careful if your key length is bigger than the ASCII value of a letter 'z' or 'Z'. In this case you should start from a letter 'a'. (e.g. key:6 letter – 'x', encrypted letter – 'd')
  • You should NOT ENCRYPT the following characters: whitespaces, and apostrophes
  • You also should replace ':' with the sign '@'

Input / Constraints

Until you receive "end" command you should read from the console.

  • Line of input – Artist name and song, separated by ":", containing only ASCII symbols.
  • Allowed working time for your program: 0.1 seconds.
  • Allowed memory: 16 MB.

Output

After every line of input, you should print:

  • If line is valid – encrypted information in following format:
  • Successful encryption: {encryptedArtist}@{encryptedSong}".
  • If line is not valid – print the following message: "Invalid input!"

 

Examples

Input

Output

Comments

Eminem:VENOM

Linkin park:NUMB

Drake:NONSTOP

Adele:HELLO

end

Successful encryption: Ksotks@BKTUS

Successful encryption: Wtyvty alcv@YFXM

Successful encryption: Iwfpj@STSXYTU

Successful encryption: Fijqj@MJQQT

All lines of input are valid, so we

encrypt the information, change the charracter ":" with the sign "@", and print the output of encription.

Example: Eminem-> key 6, adding a key to the ASCII value of each charracter except the whitespace, apostrophe, and our delimiter(":") and receive an encrypted name – Ksotks@BKTUS, then we do the same with the song.

Input

Output

Comments

Michael Jackson:ANOTHER PART OF ME

Adele:ONE AND ONLY

Guns n'roses:NOVEMBER RAIN

Christina Aguilera: HuRt

end

 

Invalid input!

Successful encryption: Fijqj@TSJ FSI TSQD

Successful encryption: Sgze z'daeqe@ZAHQYNQD DMUZ

Invalid input!

First line in not valid, because in the name of Michael Jackson we have more than one capital letter. Next two are valid, and the last is not valid, because the song does not  contain only capital letters.

 

 

 

Тест:https://judge.softuni.bg/Contests/Practice/Index/1392#1

Тагове:
0
Fundamentals Module 25/03/2019 09:51:09
willystyle avatar willystyle 2472 Точки
Best Answer

Премести инициализацията вътре в цикъла while:

bool validationArtis = false;
bool validateonSong = false;

понеже в момента при въртене на цикъла не ги инициализираш и има случай са true от преден цикъл.

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.