Skip to content

Commit 2ad30a9

Browse files
Update From PC
1 parent 2cf8c0c commit 2ad30a9

File tree

10 files changed

+441
-3
lines changed

10 files changed

+441
-3
lines changed

CyberSecurity/20.07.22-odev.c

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
struct user{
6+
int num; char name[15]; float mexam; float fexam; float grade; struct user *next;
7+
};
8+
typedef struct user node;
9+
10+
node * createList(void);
11+
void addRec(node *head);
12+
void listRec(node *head);
13+
14+
15+
int main(){
16+
int n;
17+
node *head;
18+
head= createList();
19+
20+
while(1){
21+
printf("1 for Add New Record\n");
22+
printf("2 for List Records\n");
23+
printf("\nYour Choice: "); scanf("%d",&n);
24+
25+
switch(n){
26+
case 1:
27+
addRec(head);
28+
break;
29+
case 2:
30+
listRec(head);
31+
break;
32+
}
33+
}
34+
return 0;
35+
}
36+
37+
node * createList(){
38+
int n, i;
39+
node *head, *p;
40+
printf("How many students in your list: "); scanf("%d",&n);
41+
printf("\n");
42+
43+
for(i=0; i<n; i++){
44+
if(i==0){
45+
head= (node *)calloc(1,sizeof(node));
46+
p= head;
47+
}
48+
else{
49+
p->next = (node *)calloc(1,sizeof(node));
50+
p= p->next;
51+
}
52+
printf("%d. Student's Num: ",i+1); scanf("%d",&p->num);
53+
printf("%d. Student's Name: ",i+1); scanf("%s",p->name);
54+
printf("%d. Student's Midterm Exam: ",i+1); scanf("%f",&p->mexam);
55+
printf("%d. Student's Final Exam: ",i+1); scanf("%f",&p->fexam);
56+
p->grade = (p->mexam * 0.4) + (p->fexam * 0.6);
57+
printf("\n");
58+
}
59+
p->next = NULL;
60+
printf("--------------------------------\n\n");
61+
62+
return head;
63+
}
64+
65+
void addRec(node *head){
66+
int n, i, k=1;
67+
node *p= head;
68+
printf("How many students you want to add: "); scanf("%d",&n);
69+
printf("\n");
70+
71+
while(1){
72+
if(p->next == NULL)
73+
break;
74+
p= p->next;
75+
}
76+
77+
for(i=0; i<n; i++){
78+
p->next = (node *)calloc(1,sizeof(node));
79+
p= p->next;
80+
printf("Student's Num: "); scanf("%d",&p->num);
81+
printf("Student's Name: "); scanf("%s",p->name);
82+
printf("Student's Midterm Exam: "); scanf("%f",&p->mexam);
83+
printf("Student's Final Exam: "); scanf("%f",&p->fexam);
84+
p->grade = (p->mexam * 0.4) + (p->fexam * 0.6);
85+
printf("\n");
86+
k++;
87+
}
88+
p->next = NULL;
89+
printf("--------------------------------\n\n");
90+
}
91+
92+
void listRec(node *head){
93+
char name[15];
94+
int n, number;
95+
node *p= head;
96+
97+
printf("1 for Search according to number\n");
98+
printf("2 for Search according to name\n");
99+
printf("\nYour Choice: "); scanf("%d",&n);
100+
101+
if(n == 1){
102+
printf("Enter Number: "); scanf("%d",&number);
103+
while(p != NULL){
104+
if(number == p->num){
105+
printf("\n");
106+
printf("Num: %d\n",p->num);
107+
printf("Name: %s\n",p->name);
108+
printf("Midterm Exam: %.2f\n",p->mexam);
109+
printf("Final Exam: %.2f\n",p->fexam);
110+
printf("Final Grade: %.2f\n",p->grade);
111+
break;
112+
}
113+
p= p->next;
114+
}
115+
printf("There is no student for %d number!\n",number);
116+
}
117+
else if(n == 2){
118+
printf("Enter Name: "); scanf("%s",name);
119+
while(p != NULL){
120+
if(strcmp(name, p->name) == 0){
121+
printf("\n");
122+
printf("Num: %d\n",p->num);
123+
printf("Name: %s\n",p->name);
124+
printf("Midterm Exam: %.2f\n",p->mexam);
125+
printf("Final Exam: %.2f\n",p->fexam);
126+
printf("Final Grade: %.2f\n",p->grade);
127+
break;
128+
}
129+
p= p->next;
130+
}
131+
printf("There is no student for %s name!\n",name);
132+
}
133+
else{
134+
printf("Wrong choice!\n");
135+
}
136+
137+
printf("--------------------------------\n\n");
138+
}

CyberSecurity/deneme.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
int main(){
4+
char a, b;
5+
scanf("%c %c", &a, &b);
6+
printf("%d",a*b);
7+
8+
return 0;
9+
}
10+
red

Hackerrank/3-Arrays_and_Strings/5-Dynamic_Array_in_C.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,29 @@ int main(){
1414
int total_number_of_queries;
1515
scanf("%d", &total_number_of_queries);
1616

17+
// !
18+
total_number_of_books=(int*)malloc(sizeof(int)*total_number_of_shelves);
19+
20+
total_number_of_pages=(int**)malloc(sizeof(int*)*total_number_of_shelves);
21+
22+
for(int i=0; i<total_number_of_shelves; i++){
23+
total_number_of_books[i]=0;
24+
total_number_of_pages[i]=(int*)malloc(sizeof(int));
25+
}
26+
// !
27+
1728
while (total_number_of_queries--) {
1829
int type_of_query;
1930
scanf("%d", &type_of_query);
2031

2132
if (type_of_query == 1) {
2233
int x, y;
2334
scanf("%d %d", &x, &y);
35+
2436
// !
25-
*(total_number_of_books + x) = (int *)realloc(total_number_of_books+x, )
26-
*(total_number_of_books + x) += 1;
27-
*(*(total_number_of_pages + x)) += y;
37+
*(total_number_of_books+x)+=1;
38+
*(total_number_of_pages+x)=realloc(*(total_number_of_pages+x), *(total_number_of_books+x)*sizeof(int));
39+
*(*(total_number_of_pages+x)+*(total_number_of_books+x)-1)=y;
2840
// !
2941

3042
} else if (type_of_query == 2) {
Binary file not shown.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
int lexicographic_sort(const char* a, const char* b) {
5+
strcmp(a,b);
6+
}
7+
8+
int lexicographic_sort_reverse(const char* a, const char* b) {
9+
strcmp(b,a);
10+
}
11+
12+
int characters_count(const char *s)
13+
{
14+
int n = 0;
15+
int count[128] = {0};
16+
if (NULL == s)
17+
{
18+
return -1;
19+
}
20+
while(*s != '\0')
21+
{
22+
if (!count[*s])
23+
{
24+
count[*s]++;
25+
n++;
26+
}
27+
s++;
28+
}
29+
return n;
30+
}
31+
32+
int sort_by_number_of_distinct_characters(const char* a, const char* b)
33+
{
34+
int con = characters_count(a) - characters_count(b);
35+
return (con ? con : lexicographic_sort(a, b));
36+
}
37+
38+
int sort_by_length(const char* a, const char* b) {
39+
if(strlen(a) > strlen(b))
40+
return 1;
41+
else if(strlen(a) == strlen(b))
42+
lexicographic_sort(a,b);
43+
else
44+
return 0;
45+
}
46+
47+
void string_sort(char** arr,const int len,int (*cmp_func)(const char* a, const char* b)){
48+
int i,x=0;
49+
50+
while(x != 1){
51+
x=1;
52+
for(i=0; i<len; i++){
53+
if(cmp_func(arr[i], arr[i+1]) > 0){
54+
char *temp= arr[i];
55+
arr[i]= arr[i+1];
56+
arr[i+1]= temp;
57+
x= 0;
58+
}
59+
}
60+
}
61+
}
62+
63+
64+
int main()
65+
{
66+
int n;
67+
scanf("%d", &n);
68+
69+
char** arr;
70+
arr = (char**)malloc(n * sizeof(char*));
71+
72+
for(int i = 0; i < n; i++){
73+
*(arr + i) = malloc(1024 * sizeof(char));
74+
scanf("%s", *(arr + i));
75+
*(arr + i) = realloc(*(arr + i), strlen(*(arr + i)) + 1);
76+
}
77+
78+
string_sort(arr, n, lexicographic_sort);
79+
for(int i = 0; i < n; i++)
80+
printf("%s\n", arr[i]);
81+
printf("\n");
82+
83+
string_sort(arr, n, lexicographic_sort_reverse);
84+
for(int i = 0; i < n; i++)
85+
printf("%s\n", arr[i]);
86+
printf("\n");
87+
88+
string_sort(arr, n, sort_by_length);
89+
for(int i = 0; i < n; i++)
90+
printf("%s\n", arr[i]);
91+
printf("\n");
92+
93+
string_sort(arr, n, sort_by_number_of_distinct_characters);
94+
for(int i = 0; i < n; i++)
95+
printf("%s\n", arr[i]);
96+
printf("\n");
97+
}
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#define MAX_HEIGHT 41
4+
5+
struct box
6+
{
7+
int length; int width; int height;
8+
};
9+
10+
typedef struct box box;
11+
12+
int get_volume(box b) {
13+
return b.height*b.length*b.width;
14+
}
15+
16+
int is_lower_than_max_height(box b) {
17+
if(b.height >= MAX_HEIGHT){
18+
return 0;
19+
}
20+
return 1;
21+
}
22+
23+
int main()
24+
{
25+
int n;
26+
scanf("%d", &n);
27+
box *boxes = malloc(n * sizeof(box));
28+
for (int i = 0; i < n; i++) {
29+
scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height);
30+
}
31+
for (int i = 0; i < n; i++) {
32+
if (is_lower_than_max_height(boxes[i])) {
33+
printf("%d\n", get_volume(boxes[i]));
34+
}
35+
}
36+
return 0;
37+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <math.h>
4+
5+
struct triangle
6+
{
7+
int a;
8+
int b;
9+
int c;
10+
};
11+
12+
typedef struct triangle triangle;
13+
void sort_by_area(triangle* tr, int n) {
14+
15+
triangle Ttemp;
16+
int j, i, arrN= (int *)malloc(n * sizeof(int));
17+
double p, S, Dtemp, *arrS= (double *)malloc(n * sizeof(double));
18+
for(i=0; i<n; i++){
19+
p= ((double)tr[i].a + (double)tr[i].b + (double)tr[i].c)/2;
20+
// printf("**%lf**\n",p);
21+
S= sqrt(p*(p- (double)tr[i].a)*(p- (double)tr[i].b)*(p- (double)tr[i].c));
22+
arrS[i]= S;
23+
// printf("**%lf**\n",arrS[i]);
24+
}
25+
for(i=0; i<n; i++){
26+
for(j=1; j<n; j++){
27+
if(arrS[j-1] > arrS[j]){
28+
Dtemp= arrS[j-1]; Ttemp= tr[j-1];
29+
arrS[j-1]= arrS[j]; tr[j-1]= tr[j];
30+
arrS[j]= Dtemp; tr[j]= Ttemp;
31+
}
32+
}
33+
}
34+
}
35+
36+
int main()
37+
{
38+
int n;
39+
scanf("%d", &n);
40+
triangle *tr = malloc(n * sizeof(triangle));
41+
for (int i = 0; i < n; i++) {
42+
scanf("%d%d%d", &tr[i].a, &tr[i].b, &tr[i].c);
43+
}
44+
sort_by_area(tr, n);
45+
for (int i = 0; i < n; i++) {
46+
printf("%d %d %d\n", tr[i].a, tr[i].b, tr[i].c);
47+
}
48+
return 0;
49+
}

0 commit comments

Comments
 (0)