-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ykss/master
- Loading branch information
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |