cs50

How to convert an iterative function that checks for cycles in an adjacency matrix, to a simpler, recursive function in C?

半城伤御伤魂 提交于 2020-06-16 18:41:48
问题 Having trouble grasping recursive thinking, and a lot of what I've seen on Stack overflow so far I don't understand. I'm trying to detect a cycle in a directed graph, given a 2D array adjacency matrix where a value of true for graph[i][j] indicates an edge from i to j. Have created a check_cycles function which checks for a path from j to i, given graph[i][j] and have hard coded the size of the graph to simplify the issue. I am getting a return value of true as expected with this code, but as

How to convert an iterative function that checks for cycles in an adjacency matrix, to a simpler, recursive function in C?

孤者浪人 提交于 2020-06-16 18:40:31
问题 Having trouble grasping recursive thinking, and a lot of what I've seen on Stack overflow so far I don't understand. I'm trying to detect a cycle in a directed graph, given a 2D array adjacency matrix where a value of true for graph[i][j] indicates an edge from i to j. Have created a check_cycles function which checks for a path from j to i, given graph[i][j] and have hard coded the size of the graph to simplify the issue. I am getting a return value of true as expected with this code, but as

Trouble implementing isalpha

ε祈祈猫儿з 提交于 2020-06-09 05:24:14
问题 I've been working on the readability problem in CS50. The first step is to create a way to count only the alphabetical characters. It suggests to use the isalpha function, but doesn't really include directions on how to implement it. Below is my code which succeeds in counting total alphabetical characters, but fails to filter out punctuation, spaces and integers. Could anyone point me in a better direction to implement the isalpha so that it functions? #include <stdio.h> #include <cs50.h>

Segmentation fault: boolean expression

人走茶凉 提交于 2020-06-09 05:07:47
问题 I am getting an error "Segmentation fault". I think it has to do with the isdigit(argv[i]) line but do not uderstand why. #include <stdio.h> #include <cs50.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <ctype.h> //implement commandline arguments int main(int argc, string argv[]) { //convert string element in array to integer int key = atoi(argv[1]); //check that user input for key is no more than 2 memory spots, not a negative number and a single input if (argc != 2 ||

free(): invalid pointer Aborted (core dumped) cs50

拜拜、爱过 提交于 2020-06-01 07:37:09
问题 I'm having problem with substitution cipher that I can't figure out my code functions correctly but it prints extra exclamation mark at the end of my ciphertext here is my important part of the code int keylen = strlen(argv[1]); string key = argv[1]; printf("ciphertext: "); for (int i = 0; i < keylen; i++) { //if it is a lower character we remove the value of a //to make it the letters start form 0 if (islower(plaintext[i])) { int x = plaintext[i] - 'a'; printf("%c", tolower(key[x])); } //

CS50 Pset 7 13.sql, I can't solve it, nested sqlite3 database

风格不统一 提交于 2020-05-28 08:19:33
问题 DataBase movies.db tables directors (movie_id, person_id) movies (id, title, year) people (id, name, birth) ratings (movie_id, rating, votes) stars (movie_id, person_id) you can download the database . Question I'm new in programming, so I decided, to begin with, CS50 Harvard course here is the problem and the test solution: In 13.sql, write a SQL query to list the names of all people who starred in a movie in which Kevin Bacon also starred. Your query should output a table with a single

CS50 Pset 7 13.sql, I can't solve it, nested sqlite3 database

半世苍凉 提交于 2020-05-28 08:19:28
问题 DataBase movies.db tables directors (movie_id, person_id) movies (id, title, year) people (id, name, birth) ratings (movie_id, rating, votes) stars (movie_id, person_id) you can download the database . Question I'm new in programming, so I decided, to begin with, CS50 Harvard course here is the problem and the test solution: In 13.sql, write a SQL query to list the names of all people who starred in a movie in which Kevin Bacon also starred. Your query should output a table with a single

CS50 Pset 7 13.sql, I can't solve it, nested sqlite3 database

夙愿已清 提交于 2020-05-28 08:19:07
问题 DataBase movies.db tables directors (movie_id, person_id) movies (id, title, year) people (id, name, birth) ratings (movie_id, rating, votes) stars (movie_id, person_id) you can download the database . Question I'm new in programming, so I decided, to begin with, CS50 Harvard course here is the problem and the test solution: In 13.sql, write a SQL query to list the names of all people who starred in a movie in which Kevin Bacon also starred. Your query should output a table with a single

How to add product digits rather than products themselves in C?

自闭症网瘾萝莉.ら 提交于 2020-05-15 08:01:26
问题 I am trying to finish an assignment in C for the CS50 course in which I must implement Luhn's algorithm to validate a credit card number. Here is a quick example to elaborate: credit card number: 4003600000000014. Now for every other digit, starting with the number’s second-to-last digit: 1-0-0-0-0-6-0-4 Let’s multiply each of the digits by 2: 1•2 + 0•2 + 0•2 + 0•2 + 0•2 + 6•2 + 0•2 + 4•2 That gives us: 2 + 0 + 0 + 0 + 0 + 12 + 0 + 8 Now let’s add those products’ digits (i.e., not the

PSET 4 Recover SEGMENTATION FAULT CS50

大憨熊 提交于 2020-05-14 07:12:51
问题 I'm struggling a bit with reading files and writing into files. I've been working on this problem for a few days and I just can't seem to get it. The program is supposed to recover some jpeg files from a memory card. With the following code I keep getting a segmentation fault. Can you guys see where I went wrong? Here is my code below: Hope you guys can help! #include <stdio.h> #include <stdlib.h> #include <cs50.h> int main(int argc, char *argv[]) { //Ensure only one command line argument//