시합 프로그램 설계 Tips
                                            
                                                
                                                
                                                
                                                
                                                
                                                 14530 단어  C++시합 프로그램 설계tech
                    
개요
C++에서 경기 프로그램 설계를 할 때 다시 보기 위해 필기를 합니다.
Vector
동적 정렬
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cout << v[i] << endl;
    }
}
  입력
5
0
1
2
3
4
  출력
0
1
2
3
4
  Pair
두 종류의 다른 유형을 유지할 수 있다
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    pair<int, int> p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    for (int i = 0; i < n; i++) {
        cout << p[i].first << "," << p[i].second << endl;
    }
}
  입력
5
0 1
2 3
4 5
6 7
8 9
  출력
0,1
2,3
4,5
6,7
8,9
  Map
독특한 요소를 저장하는 연상 용기에 키와value를 저장합니다
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    map<string, int> m;
    for (int i = 0; i < n; i++) {
        string k;
        int v;
        cin >> k >> v;
        m.insert(make_pair(k, v));
    }
    auto iter = m.begin();
    while (iter != m.end()) {
        cout << iter->first << "," << iter->second << endl;
        ++iter;
    }
}
  입력
5
apple 1
orange 2
banana 3
peach 4
lemon 5
  출력
apple,1
banana,3
lemon,5
orange,2
peach,4
  Set
독특한 요소를 저장하는 연상 용기
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    set<int> st;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        st.insert(x);
    }
    for (auto x : st) {
        cout << x << endl;
    }
}
  입력
5
1
2
3
1
2
  출력
1
2
3
                Reference
이 문제에 관하여(시합 프로그램 설계 Tips), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/longunder/articles/65afd49063da31텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)