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 +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; +} 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 < +#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