Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve #5 2108 통계학 & #6 2581 소수 #29

Merged
merged 8 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions problems/1181/21300875_1181.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <vector>
#include <algorithm>

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<string> v;

int line = 0;
cin >> line;

for(int i=0; i<line; i++){
string s = "";
cin >> 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<v.size(); i++){
cout << v[i] << endl;
}

return 0;
}
7 changes: 7 additions & 0 deletions problems/1967/21300875_1967.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include<iostream>
using namespace std;

int main(){
cout << "prob# 1967" << endl;
return 0;
}
70 changes: 70 additions & 0 deletions problems/2108/21300875_2108.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;

// 정렬기준
bool check(pair <int,int> &n1, pair <int,int> &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<int> v;
int sum=0; // 산술평균에 쓸 합
int num=0;

for(int i=0; i<line; i++){
cin >> 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<pair <int,int> > cnt;
for(int i=0; i<v.size(); i++){
if(cnt.empty()){
cnt.push_back(pair <int,int> (v[i],1));
continue;
}
if(cnt.back().first==v[i]){
pair<int,int> st = cnt.back();
st.second++;
cnt.pop_back();
cnt.push_back(st);
}
else{
cnt.push_back(pair <int,int> (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;
}
35 changes: 35 additions & 0 deletions problems/2581/21300875_2581.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <algorithm>

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 <<endl;
else {
cout << sum << endl;
cout << min << endl;
}

return 0;
}
33 changes: 33 additions & 0 deletions problems/4948/21300875_4948.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <vector>

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<int> 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<v.size();i++){
cout << v[i] << endl;
}

return 0;
}