asi vsetko dufam

This commit is contained in:
Aleš Novysedlák 2025-03-20 22:17:09 +01:00
parent 4a2ad2cc66
commit b09873f7d5
2 changed files with 78 additions and 26 deletions

View File

@ -1,29 +1,37 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifndef PANGRAM_H
#define PANGRAM_H
#include <stdbool.h>
bool is_pangram(const char *sentence);
#endif
// Please implement the header file from the assignment to fulfill the unit tests..
// You can add any function
#include "pangram.h"
// You can add any function
//#include "pangram.h"
bool is_pangram(const char *sentence) {
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
char is_char_contained[] = "00000000000000000000000000";
for (int i = 0; i < sizeof(sentence); i++) {
int iterator = 0;
for (int l = 0; l< 26; l++) {
if (sentence[i] == sentence[iterator]) {
is_char_contained[iterator] = 1;
break;
}
iterator++;
}
}
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
int is_char_contained[26] = {0};
int sentence_len = strlen(sentence);
for (int i = 0; i < sentence_len; i++) {
int iterator = 0;
for (int l = 0; l< 26; l++) {
if (sentence[i] == alphabet[iterator]) {
is_char_contained[iterator] = 1;
break;
}
iterator++;
}
}
for (int i = 0; i<26;i++) {
if (is_char_contained[i] == 0) return 0;
}
return 1;
for (int i = 0; i<26;i++) {
if (is_char_contained[i] == 0) return 0;
}
return 1;
return 0;
}

View File

@ -3,19 +3,27 @@
#include <ctype.h>
#include <stdlib.h>
int compare_names(const void *a, const void *b){
return strcasecmp((const char*)a, (const char*)b);
}
int compare_int(const void* a, const void* b) {
return (*(int*)b - *(int*)a);
}
int main() {
char buffer[999];
char voting[99][10];
int voting[99];
char names[99][50];
int count = 0;
while(fgets(buffer, sizeof(buffer), stdin) != NULL) {
char current_votes[10] = "";
int current_votes = 0;
char current_name[50] = "";
sscanf(buffer, "%s %[^\n]", current_votes, current_name);
sscanf(buffer, "%d %[^\n]", &current_votes, current_name);
int is_contained = 0;
for (int i=0; i<count; i++) {
if (strcmp(names[i], current_name) == 0) {
sprintf(voting[i], "%d", atoi(voting[i]) + atoi(current_votes));
voting[i] = voting[i] + current_votes;
is_contained = 1;
break;
}/*
@ -28,7 +36,7 @@ int main() {
}
if (!is_contained) {
strcpy(names[count], current_name);
strcpy(voting[count], current_votes);
voting[count] = current_votes;
count++;
}
@ -36,8 +44,44 @@ int main() {
if (count == 0) {
return 1;
}
//printf("%s %s\n", voting[0], names[0]);
int sorted_voting[99];
char names_after_sorting[99][50];
char names_while_sorting[99][50];
int number_count = 0;
int name_index = 0;
int last_number = -1;
for (int i=0;i<count;i++) {
sorted_voting[i] = voting[i];
}
qsort(sorted_voting, count, sizeof(int), compare_int);
for (int i=0;i<count;i++) {
memset(names_while_sorting, 0, sizeof(names_while_sorting));
int names_loop_index = 0;
if (sorted_voting[i] == last_number) continue;
for (int l=0;l<count;l++) {
if (sorted_voting[i] == voting[l]) {
strcpy(names_while_sorting[names_loop_index], names[l]);
number_count++;
names_loop_index++;
}
}
qsort(names_while_sorting, number_count-name_index, sizeof(char[50]), compare_names);
for (int l=0;l<number_count-name_index;l++){
strcpy(names_after_sorting[name_index+l], names_while_sorting[l]);
}
name_index = number_count;
last_number = sorted_voting[i];
}
printf("Vysledky:\n");
for (int i=0;i<count;i++) {
//printf("%d %s-------\n", voting[i], names[i]);
printf("%d %s\n", sorted_voting[i], names_after_sorting[i]);
}
return 0;
}