asi vsetko dufam
This commit is contained in:
parent
4a2ad2cc66
commit
b09873f7d5
18
a2/program.c
18
a2/program.c
@ -1,18 +1,27 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.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..
|
// Please implement the header file from the assignment to fulfill the unit tests..
|
||||||
// You can add any function
|
// You can add any function
|
||||||
#include "pangram.h"
|
//#include "pangram.h"
|
||||||
|
|
||||||
|
|
||||||
bool is_pangram(const char *sentence) {
|
bool is_pangram(const char *sentence) {
|
||||||
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
|
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
|
||||||
char is_char_contained[] = "00000000000000000000000000";
|
int is_char_contained[26] = {0};
|
||||||
for (int i = 0; i < sizeof(sentence); i++) {
|
int sentence_len = strlen(sentence);
|
||||||
|
for (int i = 0; i < sentence_len; i++) {
|
||||||
int iterator = 0;
|
int iterator = 0;
|
||||||
for (int l = 0; l< 26; l++) {
|
for (int l = 0; l< 26; l++) {
|
||||||
if (sentence[i] == sentence[iterator]) {
|
if (sentence[i] == alphabet[iterator]) {
|
||||||
is_char_contained[iterator] = 1;
|
is_char_contained[iterator] = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -25,5 +34,4 @@ bool is_pangram(const char *sentence) {
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,27 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.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() {
|
int main() {
|
||||||
char buffer[999];
|
char buffer[999];
|
||||||
char voting[99][10];
|
int voting[99];
|
||||||
char names[99][50];
|
char names[99][50];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while(fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
while(fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
||||||
char current_votes[10] = "";
|
int current_votes = 0;
|
||||||
char current_name[50] = "";
|
char current_name[50] = "";
|
||||||
sscanf(buffer, "%s %[^\n]", current_votes, current_name);
|
sscanf(buffer, "%d %[^\n]", ¤t_votes, current_name);
|
||||||
int is_contained = 0;
|
int is_contained = 0;
|
||||||
for (int i=0; i<count; i++) {
|
for (int i=0; i<count; i++) {
|
||||||
if (strcmp(names[i], current_name) == 0) {
|
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;
|
is_contained = 1;
|
||||||
break;
|
break;
|
||||||
}/*
|
}/*
|
||||||
@ -28,7 +36,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
if (!is_contained) {
|
if (!is_contained) {
|
||||||
strcpy(names[count], current_name);
|
strcpy(names[count], current_name);
|
||||||
strcpy(voting[count], current_votes);
|
voting[count] = current_votes;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +44,44 @@ int main() {
|
|||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user