cs50

Cannot figure out how to properly increment a variable inside of a while loop, C

安稳与你 提交于 2021-02-17 07:14:05
问题 EDIT: After re-writing my code in my IDE, for the 8th time today, I have made rookie mistake of giving my inputs a false data type, that has been fixed but my outputs still are incorrect. Details about my goal: When making change, odds are you want to minimize the number of coins you’re dispensing for each customer. Well, suppose that a cashier owes a customer some change and in that cashier’s drawer are quarters (25¢), dimes (10¢), nickels (5¢), and pennies (1¢). The problem to be solved is

Looking for help regarding a greedy algorithm in C for the cs50 “cash” problem set [closed]

拟墨画扇 提交于 2021-02-17 07:08:08
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 months ago . Improve this question The goal is to make an algorithm that takes an input and gives an output of the number of times the values ( 25, 10, 5, 1) are subtracted from the input. The code needs to do this in the greediest way possible, taking the highest value whenever its possible. Expected output

CS50x - Filter (blur) - Receiving a runtime error on first nested else state + seeking for feedback on length of code

亡梦爱人 提交于 2021-02-11 17:37:27
问题 Terminal photo HERE!I'm currently having a runtime error and have tried modifying my code but it will not pass. If there is any specific pointers I could get (no pun intended) to help me approach this issue. I'm also seeking some feedback on the length of my code - I wrote it as it came to my head and I'm aware that I could make this more short and coherent. I'm currently working on filtering each independent pixel within the image grid. Would one suggest writing code as it comes to our head

CS50 pset5 speller line 54 conditional jump error

醉酒当歌 提交于 2021-02-11 14:21:27
问题 When I compile and run my code it sort of looks like the code works, but when I run Valgrind with help50, it says "==1295== Conditional jump or move depends on uninitialized value(s)" I don't get how to fix this problem. Help50 tells me to focus on line 54 of my code, but I don't understand what is wrong, it was working before, now it is a mistake. What I don't understand is what the mistake is/ #include <ctype.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h>

CS50 pset5 speller line 54 conditional jump error

拜拜、爱过 提交于 2021-02-11 14:20:21
问题 When I compile and run my code it sort of looks like the code works, but when I run Valgrind with help50, it says "==1295== Conditional jump or move depends on uninitialized value(s)" I don't get how to fix this problem. Help50 tells me to focus on line 54 of my code, but I don't understand what is wrong, it was working before, now it is a mistake. What I don't understand is what the mistake is/ #include <ctype.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h>

Counting repeated STR in DNA PSET6 CS50

試著忘記壹切 提交于 2021-02-11 14:12:02
问题 Currently working on CS50. I tried to count STR in file DNA Sequences but it always overcount. I mean, for example: how much 'AGATC' in file DNA repeat consecutively. This code is only try to find out how to count those repeated DNA accurately. import csv import re from sys import argv, exit def main(): if len(argv) != 3: print("Usage: python dna.py data.csv sequence.txt") exit(1) with open(argv[1]) as csv_file, open(argv[2]) as dna_file: reader = csv.reader(csv_file) #for row in reader: #

How to find the max. number of times a sequence of characters repeats consecutively in Python?

余生颓废 提交于 2021-02-10 14:49:01
问题 I'm working on a cs50/pset6/dna project. I'm struggling with finding a way to analize a sequence of strings, and gather the maximum number of times a certain sequence of characters repeats consecutively. Here is an example: String: JOKHCNHBVDBVDBVDJHGSBVDBVD Sequence of characters I should look for: BVD Result: My function should be able to return 3 , because in one point the characters BVD repeat three times consecutively, and even though it repeats again two times, I should look for the

How to find the max. number of times a sequence of characters repeats consecutively in Python?

我与影子孤独终老i 提交于 2021-02-10 14:45:17
问题 I'm working on a cs50/pset6/dna project. I'm struggling with finding a way to analize a sequence of strings, and gather the maximum number of times a certain sequence of characters repeats consecutively. Here is an example: String: JOKHCNHBVDBVDBVDJHGSBVDBVD Sequence of characters I should look for: BVD Result: My function should be able to return 3 , because in one point the characters BVD repeat three times consecutively, and even though it repeats again two times, I should look for the

Greedy Program Running Forever

大兔子大兔子 提交于 2021-02-10 14:36:42
问题 I recently developed a simple program designed to take a certain amount of money (in dollars) and determine the least number of coins necessary to fulfill that requirement. #include <stdio.h> #include <cs50.h> int main(void) { // prompts for change and assigns variable owed_change that value float owed_change = -1; while (owed_change < 0 ) { printf("How much change is owed?\n"); owed_change = GetFloat(); } // sets the varialble n_coins to 0 int n_coins = 0; // repeats until no more change is

How to check for repeated characters within a string in c

不问归期 提交于 2021-02-10 05:20:32
问题 I'm trying to create a program that checks for repeated characters within the command line argument's string. The string is suppose to contain only 26 characters, and all characters have to be alphabetical. However, there cannot be any repeated characters within the string, each alphabetical character must appear only once. I figured out the first two sections of the program but I cant figure out how to check for repeated characters. I could really use some help as well as explanations.