Safety Deposit Boxes task (in C) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

25th Apr 2020, 8:10 PM
Денис Филь
Денис Филь - avatar
18 Answers
+ 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
25th Apr 2020, 9:20 PM
Денис Филь
Денис Филь - avatar
+ 1
could you please add also aim of the solution.
25th Apr 2020, 8:41 PM
george
george - avatar
+ 1
you have incorrect while. do tou speak russian? while (pToken != NULL){ totalTime += TIME; if (strcmp (pToken , key) == 0 ) { break; } pToken = strtok (NULL , ","); }
25th Apr 2020, 9:41 PM
george
george - avatar
+ 1
Да
25th Apr 2020, 9:50 PM
Денис Филь
Денис Филь - avatar
+ 1
Почему он некорректный? Не могу разобраться.
25th Apr 2020, 9:51 PM
Денис Филь
Денис Филь - avatar
+ 1
ia cam vislal while posmotrite i sravnite!!!
25th Apr 2020, 9:57 PM
george
george - avatar
+ 1
u vas tam v while shotaetsa kolfo slov potom esli slovo naxoditsa vishitivaetsa total i prodoljaetsa viponenie koda xoti doljen srazuje zakonchitsa
25th Apr 2020, 9:58 PM
george
george - avatar
+ 1
ne znau nujno li proverat esli nujnogo slova voobshe netu v spiske no dumau chto takaia zadacha ne stoit
25th Apr 2020, 9:59 PM
george
george - avatar
+ 1
Да нет, сама логика верная. Что с функцией fgets, т.к. если ее поменять на gets, то все работает и задача решена. Но не могу понять что не так делаю использую fgets
25th Apr 2020, 10:01 PM
Денис Филь
Денис Филь - avatar
+ 1
А все разобрался!!! Fgets считывает \0 в последнем слове, поэтому на последнем слове не срабатывает IF
25th Apr 2020, 10:04 PM
Денис Филь
Денис Филь - avatar
+ 1
Т.е. если искомое слово последнее в строкe items, то strcmp сравнивает и выдает разницу на \0
25th Apr 2020, 10:07 PM
Денис Филь
Денис Филь - avatar
+ 1
So I've found the problem. Fgets get the '\0' symbol.
25th Apr 2020, 10:10 PM
Денис Филь
Денис Филь - avatar
+ 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
25th Apr 2020, 10:10 PM
george
george - avatar
+ 1
Нет он проходит все. Если вставить printf("%i", nWords) в тело цикла то вывода верное количество слов в строке включая последнее искомое (если их несколько в строке).
25th Apr 2020, 10:14 PM
Денис Филь
Денис Филь - avatar
+ 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
25th Apr 2020, 10:41 PM
george
george - avatar
+ 1
https://code.sololearn.com/cO6KG3BitLxZ/?ref=app vot kod ulichil i poxodu sdelal komentarii
25th Apr 2020, 10:42 PM
george
george - avatar
+ 1
ochen slojno pisat kod s mobilnogo iphone 5s )))) poetomi i tak dolgo)
25th Apr 2020, 10:44 PM
george
george - avatar
+ 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
26th Apr 2020, 10:20 AM
manjeet gupta
manjeet gupta - avatar