From a5e6a86ea9442ee70fd47f21bbea08ea02b80034 Mon Sep 17 00:00:00 2001 From: ykss Date: Fri, 29 Mar 2019 02:28:48 +0900 Subject: [PATCH 1/7] solve prob#5 --- problems/2108/21300875.cpp | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 problems/2108/21300875.cpp diff --git a/problems/2108/21300875.cpp b/problems/2108/21300875.cpp new file mode 100644 index 0000000..9b81a63 --- /dev/null +++ b/problems/2108/21300875.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +using namespace std; + +// 정렬기준 +bool check(pair &n1, pair &n2){ + if (n1.second==n2.second) return n1.first < n2.first; + else return n1.second > n2.second; +} + +int main () { + + //라인 수 받기 + int line = 0; + cout << "입력할 정수의 개수를 알려주세요. : " ; + cin >> line; + + vector v; + int sum=0; // 산술평균에 쓸 합 + int num=0; + + for(int i=0; i> num; + v.push_back(num); + sum += num; + } + cout << endl; + + //산술평균 + int avg = 0; + avg = round((float)sum/line); + cout << avg << endl; + //중간값 출력 + sort(v.begin(),v.end()); + cout << v[line/2] << endl; + //최빈값 출력 + vector > cnt; + for(int i=0; i (v[i],1)); + continue; + } + if(cnt.back().first==v[i]){ + pair st; + st = cnt.back(); + st.second++; + cnt.pop_back(); + cnt.push_back(st); + } + else{ + cnt.push_back(pair (v[i],1)); + } + } + + //최빈값순으로 정렬해야함. + sort(cnt.begin(), cnt.end(), check); + // 최빈값이 같을땐 두번째 작은 값 출력 + if (cnt[0].second == cnt[1].second) + cout << cnt[1].first << endl; + else + cout << cnt[0].first << endl; + + //범위 출력 + cout << v.back()-v.front() << endl; + + return 0; +} From 2b2fd77321b70b680453dc5d43a30293eb67bc6a Mon Sep 17 00:00:00 2001 From: ykss Date: Fri, 29 Mar 2019 02:38:39 +0900 Subject: [PATCH 2/7] solve prob#5 fix --- problems/2108/21300875.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/problems/2108/21300875.cpp b/problems/2108/21300875.cpp index 9b81a63..892f1b7 100644 --- a/problems/2108/21300875.cpp +++ b/problems/2108/21300875.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; // 정렬기준 @@ -14,7 +15,6 @@ int main () { //라인 수 받기 int line = 0; - cout << "입력할 정수의 개수를 알려주세요. : " ; cin >> line; vector v; @@ -32,9 +32,11 @@ int main () { int avg = 0; avg = round((float)sum/line); cout << avg << endl; + //중간값 출력 sort(v.begin(),v.end()); cout << v[line/2] << endl; + //최빈값 출력 vector > cnt; for(int i=0; i st; - st = cnt.back(); + pair st = cnt.back(); st.second++; cnt.pop_back(); cnt.push_back(st); From 6e3b9af56fe1162bf457d650381d1c87b2a5144e Mon Sep 17 00:00:00 2001 From: ykss Date: Fri, 29 Mar 2019 03:11:04 +0900 Subject: [PATCH 3/7] solve prob#15 --- problems/2581/21300875_2581.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 problems/2581/21300875_2581.cpp diff --git a/problems/2581/21300875_2581.cpp b/problems/2581/21300875_2581.cpp new file mode 100644 index 0000000..3234566 --- /dev/null +++ b/problems/2581/21300875_2581.cpp @@ -0,0 +1,35 @@ +#include +#include + +using namespace std; + +bool isprime(int n) { + if(n < 2) return false; + for(int i=2; i*i<=n; i++){ + if (n%i == 0) + return false; + } + return true; +} + +int main() { + int m = 0, n = 0; + cin >> m; + cin >> n; + + int sum = 0, min = 10000; + + for (int i = m; i < n+1; i++){ + if(isprime(i)){ + sum+=i; + if(min>i) min=i; + } + } + if(min==10000) cout << -1 < Date: Mon, 1 Apr 2019 19:22:54 +0900 Subject: [PATCH 4/7] solve prob#1181 --- problems/1181/21300875_1181.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 problems/1181/21300875_1181.cpp diff --git a/problems/1181/21300875_1181.cpp b/problems/1181/21300875_1181.cpp new file mode 100644 index 0000000..45aaaa8 --- /dev/null +++ b/problems/1181/21300875_1181.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +bool compare(string &s1, string &s2){ + if(s1.size() == s2.size()) return s1 < s2; + else return s1.size() < s2.size(); +} + +int main () { + vector v; + + int line = 0; + cin >> line; + + for(int i=0; i> s; + v.push_back(s); + } + sort(v.begin(),v.end(),compare); + + v.erase(unique(v.begin(), v.end()), v.end()); + + for(int i=0;i Date: Fri, 5 Apr 2019 10:29:33 +0900 Subject: [PATCH 5/7] filename fix --- problems/2108/21300875.cpp | 70 -------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 problems/2108/21300875.cpp diff --git a/problems/2108/21300875.cpp b/problems/2108/21300875.cpp deleted file mode 100644 index 892f1b7..0000000 --- a/problems/2108/21300875.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -// 정렬기준 -bool check(pair &n1, pair &n2){ - if (n1.second==n2.second) return n1.first < n2.first; - else return n1.second > n2.second; -} - -int main () { - - //라인 수 받기 - int line = 0; - cin >> line; - - vector v; - int sum=0; // 산술평균에 쓸 합 - int num=0; - - for(int i=0; i> num; - v.push_back(num); - sum += num; - } - cout << endl; - - //산술평균 - int avg = 0; - avg = round((float)sum/line); - cout << avg << endl; - - //중간값 출력 - sort(v.begin(),v.end()); - cout << v[line/2] << endl; - - //최빈값 출력 - vector > cnt; - for(int i=0; i (v[i],1)); - continue; - } - if(cnt.back().first==v[i]){ - pair st = cnt.back(); - st.second++; - cnt.pop_back(); - cnt.push_back(st); - } - else{ - cnt.push_back(pair (v[i],1)); - } - } - - //최빈값순으로 정렬해야함. - sort(cnt.begin(), cnt.end(), check); - // 최빈값이 같을땐 두번째 작은 값 출력 - if (cnt[0].second == cnt[1].second) - cout << cnt[1].first << endl; - else - cout << cnt[0].first << endl; - - //범위 출력 - cout << v.back()-v.front() << endl; - - return 0; -} From c1749150cc226b55a951fd7ea2b3cc52a6cd7aa8 Mon Sep 17 00:00:00 2001 From: ykss Date: Fri, 5 Apr 2019 10:33:25 +0900 Subject: [PATCH 6/7] filename fix --- problems/1967/21300875_1967.cpp | 7 ++++ problems/2108/21300875_2108.cpp | 70 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 problems/1967/21300875_1967.cpp create mode 100644 problems/2108/21300875_2108.cpp diff --git a/problems/1967/21300875_1967.cpp b/problems/1967/21300875_1967.cpp new file mode 100644 index 0000000..a97d38e --- /dev/null +++ b/problems/1967/21300875_1967.cpp @@ -0,0 +1,7 @@ +#include +using namespace std; + +int main(){ + cout << "prob# 1967" << endl; + return 0; +} diff --git a/problems/2108/21300875_2108.cpp b/problems/2108/21300875_2108.cpp new file mode 100644 index 0000000..892f1b7 --- /dev/null +++ b/problems/2108/21300875_2108.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +using namespace std; + +// 정렬기준 +bool check(pair &n1, pair &n2){ + if (n1.second==n2.second) return n1.first < n2.first; + else return n1.second > n2.second; +} + +int main () { + + //라인 수 받기 + int line = 0; + cin >> line; + + vector v; + int sum=0; // 산술평균에 쓸 합 + int num=0; + + for(int i=0; i> num; + v.push_back(num); + sum += num; + } + cout << endl; + + //산술평균 + int avg = 0; + avg = round((float)sum/line); + cout << avg << endl; + + //중간값 출력 + sort(v.begin(),v.end()); + cout << v[line/2] << endl; + + //최빈값 출력 + vector > cnt; + for(int i=0; i (v[i],1)); + continue; + } + if(cnt.back().first==v[i]){ + pair st = cnt.back(); + st.second++; + cnt.pop_back(); + cnt.push_back(st); + } + else{ + cnt.push_back(pair (v[i],1)); + } + } + + //최빈값순으로 정렬해야함. + sort(cnt.begin(), cnt.end(), check); + // 최빈값이 같을땐 두번째 작은 값 출력 + if (cnt[0].second == cnt[1].second) + cout << cnt[1].first << endl; + else + cout << cnt[0].first << endl; + + //범위 출력 + cout << v.back()-v.front() << endl; + + return 0; +} From 62dae641833f2113fbd89f43e0a62b3ae120aac3 Mon Sep 17 00:00:00 2001 From: ykss Date: Fri, 5 Apr 2019 10:38:21 +0900 Subject: [PATCH 7/7] solve 4948 --- problems/4948/21300875_4948.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 problems/4948/21300875_4948.cpp diff --git a/problems/4948/21300875_4948.cpp b/problems/4948/21300875_4948.cpp new file mode 100644 index 0000000..189f5f8 --- /dev/null +++ b/problems/4948/21300875_4948.cpp @@ -0,0 +1,33 @@ +#include +#include + +using namespace std; + +bool isprime(int n) { + if(n < 2) return false; + for(int i=2; i*i<=n; i++){ + if (n%i == 0) + return false; + } + return true; +} + +int main() { + int N = 0; + vector v; + while(1){ + int cnt = 0; + cin >> N; + if(N==0) break; + for(int i=N+1;i<=2*N;i++){ + if(isprime(i)) cnt++; + } + v.push_back(cnt); + } + + for(int i=0;i