1주차 (07/03) - Class 2
10989 - 수 정렬하기 3
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int testCase;
vector <int> numList(10001, 0);
cin >> testCase;
for (int i=0; i<testCase; i++) {
int num;
cin >> num;
numList[num]++;
}
for (int i=1; i<=10000; i++)
for (int j=0; j<numList[i]; j++)
cout << i << "\n";
return 0;
}
11050 - 이항 계수 1
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, r, result = 1;
cin >> n >> r;
for (int i = n; i > 1; i--) {
result *= i;
if (i <= r)
result /= i;
if (i <= n - r)
result /= i;
}
cout << result;
return 0;
}
1181 - 단어 정렬
#include <iostream>
#include <string>
#include <list>
using namespace std;
bool cmp(string first, string second) {
if (first.length() != second.length())
return first.length() < second.length();
return first < second;
}
int main() {
list <string> strList;
int num;
cin >> num;
for (int i=0; i<num; i++) {
string str;
cin >> str;
strList.push_back(str);
}
strList.sort(cmp);
strList.unique();
for (string s:strList)
cout << s << "\n";
return 0;
}
1436 - 영화감독 숌
#include <iostream>
#include <string>
using namespace std;
int main() {
int num, result = 665;
cin >> num;
while (num) {
result++;
if (to_string(result).find("666") != string::npos)
num--;
}
cout << result;
return 0;
}
1978 - 소수 찾기
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num) {
if (num <= 1)
return false;
for (int i=2; i<=sqrt(num); i++)
if (num % i == 0)
return false;
return true;
}
int main() {
int times, result = 0;
cin >> times;
for (int i=0; i<times; i++) {
int num;
cin >> num;
if (isPrime(num))
result++;
}
cout << result;
return 0;
}