Skip to content

Commit

Permalink
Merge pull request #33 from gksksla/master
Browse files Browse the repository at this point in the history
Solve #5 2108 통계학 & #6 2581 소수
  • Loading branch information
Yongho Lee committed Apr 8, 2019
2 parents adb7422 + 5c8fa4a commit d7d67e5
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
65 changes: 65 additions & 0 deletions problems/2108/21900398.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d", &n);
int x;
char arr[5000];
for (x = 0; x < n; x++)
{
scanf("%d", &arr[x]);
}
int len=strlen(arr);//길이 구하기 찾기
//1. sum구하고
int sum = 0;
for (x = 0; x < len; x++)
{
sum += arr[x];
}
//2. sum/N값 구하기
printf("%d\n", sum / n);
//3. arr를 sort
int a, b;
for (a = 0; a < len - 1; a++)
{
for (b = a + 1; b < len; b++)
{
if (arr[a] > arr[b])
{
int temp;
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;

}
}
}
//4. arr[N/2+1]출력
printf("%d\n", arr[n / 2 ]);
//5. count배열만들고
int count[200] = { 0 };
for (x = 0; x < len; x++)
{
count[arr[x]]++;
}
//6. count배열이용해서 최빈값찾기
int Max = count[0];
int many;
for (x = 0; x < len; x++)
{
if (count[x] > Max)
{
Max = count[x];
many = x;
}

}
printf("%d\n", many);


//8. max-min출력
printf("%d", arr[len-1] - arr[0]);


return 0;
50 changes: 50 additions & 0 deletions problems/2581/21900398.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<stdio.h>
#include<string.h>
int main()
{
char arr[100] = { 0 };
int t = 0;
int m, n;
scanf("%d\n%d", &m, &n);
int i;
int a;
int flag = 0;
for (i = m; i <= n; i++)
{
for (a = 2; a < i; a++)
{
if (i%a == 0)
{
flag = 0;
break;
}
else
{
flag = 1;

}
}
if (flag == 1)
{
arr[t] = i;
t++;
}
}
int len = strlen(arr);
if (len == 0)
{
printf("-1");
return 0;
}
int sum = 0;
int x;

for (x = 0; x < len; x++)
{
sum += arr[x];
}

printf("%d %d", sum, arr[0]);
return 0;

}

0 comments on commit d7d67e5

Please sign in to comment.