Safety Deposit Boxes task (in C) | Sololearn: Learn to code for FREE!

+1

Safety Deposit Boxes task (in C)

I've written some code for solving this task. But I can't understand why it doesn't solve this task. https://code.sololearn.com/conASqHMWimL/?ref=app

4/25/2020 8:10:13 PM

Денис Филь

18 Answers

New Answer

+2

Safety Deposit Boxes +50 XP You are robbing a bank, but you’re not taking everything. You are looking for a specific item in the safety deposit boxes and you are going to drill into each one in order to find your item. Once you find your item you can make your escape, but how long will it take you to get to that item? Task Determine the amount of time it will take you to find the item you are looking for if it takes you 5 minutes to drill into each box. Input Format A string that represent the items in each box that will be drilled in order (items are separated by a comma), and secondly, a string of which item you are looking for. Output Format An integer of the amount of time it will take for you to find your item. Sample Input 'gold,diamonds,documents,Declaration of Independence,keys' 'Declaration of Independence' Sample Output 20

+1

could you please add also aim of the solution.

+1

you have incorrect while. do tou speak russian? while (pToken != NULL){ totalTime += TIME; if (strcmp (pToken , key) == 0 ) { break; } pToken = strtok (NULL , ","); }

+1

+1

Почему он некорректный? Не могу разобраться.

+1

ia cam vislal while posmotrite i sravnite!!!

+1

u vas tam v while shotaetsa kolfo slov potom esli slovo naxoditsa vishitivaetsa total i prodoljaetsa viponenie koda xoti doljen srazuje zakonchitsa

+1

ne znau nujno li proverat esli nujnogo slova voobshe netu v spiske no dumau chto takaia zadacha ne stoit

+1

Да нет, сама логика верная. Что с функцией fgets, т.к. если ее поменять на gets, то все работает и задача решена. Но не могу понять что не так делаю использую fgets

+1

А все разобрался!!! Fgets считывает \0 в последнем слове, поэтому на последнем слове не срабатывает IF

+1

Т.е. если искомое слово последнее в строкe items, то strcmp сравнивает и выдает разницу на \0

+1

So I've found the problem. Fgets get the '\0' symbol.

+1

ia shas posmotrel ia v C ne silen, v c++ rabotau no u vas tam while ne pravilno sobran, etot while beret 1 slovo a dalshe ne idet na vtoroe, printami proveral, i potomy. organiziite pravilno while

+1

Нет он проходит все. Если вставить printf("%i", nWords) в тело цикла то вывода верное количество слов в строке включая последнее искомое (если их несколько в строке).

+1

ia nashel oshibku))) ona me iza vas a izza sololearn test cora. kogda vi vvodite stroku 1,2,3,4 4 naprimer to on v pervoi stroke na konce prixvativaet \n i iza etogo poslednaia proverka ne proxodit

+1

https://code.sololearn.com/cO6KG3BitLxZ/?ref=app vot kod ulichil i poxodu sdelal komentarii

+1

ochen slojno pisat kod s mobilnogo iphone 5s )))) poetomi i tak dolgo)

+1

import re x=input() y=input() pattern=re.compile("[^,]+") search=pattern.findall(x) z=search.index(y) time=5*(int(z)+1) print(time) Above are python code