[C++] 백준 1302 베스트셀러
·
Algorithm/Baekjoon
#include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); map book; string name; int n, m = 0; cin >> n; while (n > 0) { cin >> name; book[name] += 1;//있거나 없으면 1추가 *중복된 이름이 없음 n--; } name = ""; for (auto ptr = book.begin(); ptr != book.end(); ptr++) {//first와 second불러오면서 비교 if (m second)//값이 max인것의 이름을 계속적어줌 { m = ptr->second; name =..
[C++] 백준 1568 새
·
Algorithm/Baekjoon
#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int num = 0, n, m = 1; cin >> n; while (n > 0) { if (n >= m)//부르려는 수가 새보다 적을 때 { n -= m;//총 새에 부르는 수 감소 num++; //카운트 m++; //부르는 수 증가 } else//총남은 새가 부르려는 수보다 적을 때 { m = 1; } } cout
[C++] 백준 1543 문서 검색
·
Algorithm/Baekjoon
#include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); string n; string m; int result = 0; getline(cin, n);//공백까지 단어로 포함 getline(cin, m); for (int i = 0; i < n.length();) { if (n.substr(i, m.length()) == m)//i부터 단어의 길이까지가 단어와 같나 { i += m.length();//같으면 검색한 길이만큼 제외 result++;//같은 개수 추가 } else { i++;//없으면 한 글자 추가 } } cout
[C++] 백준 10814 나이순 정렬
·
Algorithm/Baekjoon
#include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector x; for (int i = 0; i > temp >> temp2; x.push_back({ temp, i, temp2 }); } sort(x.begin(), x.end()); for (int i = 0; i < n; i++) { cout
[C++] 백준 1427 소트인사이드
·
Algorithm/Baekjoon
#include #include #include using namespace std; int main() { ios::sync_with_stdio(false); string n; cin >> n; sort(n.rbegin(), n.rend()); int num = stoi(n);//string에 있는 stoi함수를 사용하여 int로 형변환한다. //s(tring)to(int) stoi로 생각 cout
[C++] 백준 1920 수 찾기
·
Algorithm/Baekjoon
#include #include #include using namespace std; int main() { set num; vector finding; int n, m, temp; cin >> n; for (int i = 0; i > temp; num.insert(temp); } cin >> m; for (int i = 0; i > temp; finding.push_back(temp); } for (auto x : finding) { cout