Loading...

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

Zeltops avatar Zeltops 0 Точки

01. Arriving in Kathmandu - Technology Fundamentals Final Exam - 14 April 2019 Group I

Judge ми дава 80/100, ако някой може да ми даде правилно решение или да ми помогне с моето ще му бъда много благодарен.

Ето моето решение: https://pastebin.com/pf5x04z0

Условието: https://judge.softuni.bg/Contests/1516/Technology-Fundamentals-Final-Exam-14-April-2019-Group-I

или:

Write a program that decrypts messages, which contain information about coordinates. You are looking for names of peaks in the Himalayas and their geohash coordinates. Keep reading lines until you receive the "Last note" message.

Here is your cipher:

  • Name of the peak
    • It is consisted of letters (upper and lower), numbers and some of the following characters between its letters – "!" "@" "#" "$" "?". Example for valid names: “!@K?#2!#” (K2).
  • The length of the geohashcode
    • Begins after the "=" (equals) sign and is consisted only of numbers.
  • The geohash code
    • Begins after these symbols – "<<", may contain anything and the message always ends with it.

Examples for valid input:

"!Ma$$ka!lu!@=9<<ghtucjdhs" – all the components are there – name of the peek, length of the geohashcode and a geohashcode.

"!@Eve?#rest!#=7<<vbnfhfg"

Examples of invalid input:

"anna@fg<<jhsd@bx!=4" – their order is wrong. The name should be first, the length after and the code last.

"#n...s!n-<<tyuhgf4" – the length is missing and the name contains dots.

"Nan$ga!Parbat=8<<gh2tn – the length of the geohash code doesn't match the given number.

The geohash code you are looking for is with length exactly as much as the given length in the message and the information must be in the exact given order, otherwise it is considered invalid. If you find it, print the following message:

"Coordinates found! {nameOfMountain} -> {geohashcode}"

Otherwise print: “Nothing found!” after every invalid message.

Input / Constraints

  • You will be receiving strings until you get the “Last note” message.

Output

  • If you find the right coordinates, print: "Coordinates found! {nameOfMountain} -> {geohashcode}".
  • If the message is invalid, print: "Nothing found!".

Examples

Input

Output

!@Ma?na?sl!u@=7<<tv58ycb4845

E!ve?rest=.6<<tuvz26

!K@2.,##$=4<<tvnd

!Shiha@pan@gma##9<<tgfgegu67

!###Anna@pur@na##=16<<tv5dekdz8x11ddkc

Last note

Nothing found!

Nothing found!

Nothing found!

Nothing found!

Coordinates found! Annapurna -> tv5dekdz8x11ddkc

Comments

The first line is invalid, because the length – 7, doesn't match the length of the code.

The second line is invalid, because the length should be consisted only of numbers.

The third line is invalid, because the name contains symbols that are not allowed – ".", ",".

The forth line is invalid, because the "=" sign before the length is missing.

The fifth line is valid, so we print the appropriate message.

 

Ka?!#nch@@en@ju##nga@=3<<thfbghvn

=9Cho?@#Oyu<<thvb7ydht

Nan??ga#Par!ba!t?=16<<twm03q2rx5hpmyr6

Dhau??la#gi@ri?!#=3<<bvnfhrtiuy

Last note

Nothing found!

Nothing found!

Coordinates found! NangaParbat -> twm03q2rx5hpmyr6

Nothing found!

Тагове:
0
Module: C# Advanced
msmner avatar msmner 38 Точки
Best Answer

Ето едно с РегЕкс:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace Extract_Emails
{
    class Program
    {
        static void Main(string[] args)
        {
            string pattern = @"^(?<nameofpeak>[A-Za-z0-9!@#$?]+)=(?<length>\d+)<<(?<code>(.*?)+)$";
            string input;
            Regex regex = new Regex(pattern);
            while ((input=Console.ReadLine())!="Last note")
            {
                Match match = regex.Match(input);
                if (match.Success == false)
                {
                    Console.WriteLine("Nothing found!");
                    continue;
                }
                string nameOfPeak = match.Groups["nameofpeak"].Value;
                int length = int.Parse(match.Groups["length"].Value);
                string code = match.Groups["code"].Value;
                string nameOfPeakResult = string.Empty;
                if (code.Length != length)
                {
                    Console.WriteLine("Nothing found!");
                    continue;
                }

                for (int i = 0; i < nameOfPeak.Length; i++)
                {
                    if (char.IsLetterOrDigit(nameOfPeak[i]))
                    {
                        nameOfPeakResult += nameOfPeak[i];
                    }
                }

                Console.WriteLine($"Coordinates found! {nameOfPeakResult} -> {code}");
            }
        }
    }
}

 

0
dyakoale avatar dyakoale 0 Точки

Здравейте колеги,

 

Ето мойто (Java) решение с regex: https://pastebin.com/LJTMBfkX

Проблема е , че Judge ми дава 90/100 и не мога да си открия грешката. Забележете че ако подменя регекса с : 

//"(?<name>.*?[!@#$?]+[A-Za-z+0-9]+[!@#$?]+)=(?<length>[0-9]+)<<(?<code>.*$)";

изкарвам само 20 от 100, което ме навежда на мисълта че нередното тук е в регекса, а не в кода.

Някой има ли идеи как да се направи?

 

Благодаря предварително!

0
Mihail.Tomov92 avatar Mihail.Tomov92 2 Точки

Привет!

Проблемът ти според мен е в тази проверка:

if (Character.isLetter(letter))

Тук се търси isLetterOrDigit или както се подава метода на Java понеже аз съм със C#. Цитат от задачата защо "Example for valid names: “!@K?#2!#” (K2)"

И аз подобно на теб изгубих 1-2 часа да си човъркам регекса при 90/100 преди да обърна внимание на този детайл :D

Успех и дано съм помогнал!

0
Angello avatar Angello 1 Точки

да си жив и здрав

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