AD

수다 오늘방송도 기대합니다. (부담 ㄴㄴ)

to0869
2019-01-13 15:18:25 175 0 6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cctype> 
 
class Person {
    std::string name;
    int age;
public:
    Person() = default;
    Person(std::string name, int age) 
        : name{name}, age{age}  {}
    bool operator<(const Person &rhs) const {
        return this->age < rhs.age;
    }
    bool operator==(const Person &rhs) const {
        return (this->name == rhs.name && this->age == rhs.age);
    }
};
 
// Find an element in a container
void find_test() {
    std::cout << "\n========================" << std::endl;
 
    std::vector<int> vec {1,2,3,4,5};
    
    auto loc = std::find(std::begin(vec), std::end(vec), 1);//equivalent to vec.begin(), 
    
    if (loc != std::end(vec))
        std::cout << "Found the number: " << *loc <<  std::endl;
    else 
        std::cout << "Couldn't find the number" << std::endl;
        
    std::list<Person> players {
        {"Larry", 18},
        {"Moe", 20},
        {"Curly", 21}
    };
    
    auto loc1 = std::find(players.begin(), players.end(), Person{"Moe", 20});
    if (loc1 != players.end())
        std::cout << "Found  Moe" << std::endl;
    else
        std::cout << "Moe not found" << std::endl;
}
 
// Count the number of elements in a container
void count_test() {
    std::cout << "\n========================" << std::endl;
 
     std::vector<int> vec {1,2,3,4,5,1,2,1};
     
     int num = std::count(vec.begin(), vec.end(), 1);
     std::cout << num << " occurrences found" << std::endl;
}
 
// Count the number of occurences of an element in a container
// based on a predicate using a lambda expression
 
void count_if_test() {
    std::cout << "\n========================" << std::endl;
 
    // count only if the element is even
    std::vector<int> vec {1,2,3,4,5,1,2,1,100};
    int num = std::count_if(vec.begin(), vec.end(), [](int x) { return x %2 == 0; });
    std::cout << num << " even numbers found" << std::endl;
    
    num = std::count_if(vec.begin(), vec.end(), [](int x) { return x %2 != 0; });
    std::cout << num << " odd numbers found" << std::endl;
    
    // how can we determine how many elements in vec are >= 5?
    num = std::count_if(vec.begin(), vec.end(), [](int x) { return x>=5;   });
    std::cout << num << "  numbers are >= 5" << std::endl;
 
}
 
// Replace occurrences of elements in a container
void replace_test() {
    std::cout << "\n========================" << std::endl;
 
     std::vector<int> vec {1,2,3,4,5,1,2,1};
     for (auto i: vec) {
         std::cout << i << " ";
     }
     std::cout << std::endl;
     
    std::replace(vec.begin(), vec.end(), 1, 100);
    for (auto i: vec) {
         std::cout << i << " ";
     }
    std::cout << std::endl;
}
 
void all_of_test() {
    std::vector<int> vec1 {1,3,5,7,9,1,3,13,19,5};
    if (std::all_of(vec1.begin(), vec1.end(), [](int x) { return x > 10; }))
        std::cout << "All the elements are > 10" << std::endl;
    else    
        std::cout << "Not all the elements are > 10" << std::endl;
    
    if (std::all_of(vec1.begin(), vec1.end(), [](int x) { return x < 20; }))
        std::cout << "All the elements are < 20" << std::endl;
    else    
        std::cout << "Not all the elements are < 20" << std::endl;        
}
 
// Transform elements in a container - string in this example
void string_transform_test() {
    std::cout << "\n========================" << std::endl;
 
    std::string str1 {"This is a test"};
    std::cout << "Before transform: " << str1 << std::endl;
    std::transform(str1.begin(), str1.end(), str1.begin(), ::toupper);// :: global scope
    std::cout << "After transform: " << str1 << std::endl;
}
 
cs


흠....

후원댓글 6
댓글 6개  
이전 댓글 더 보기
이 글에 댓글을 달 권한이 없습니다. 로그인해 보세요.
▲윗글 따흐찌 에디션이 도착 그루치
공지방송일정따찌의 일기수다이벤트트수타그램그림팬아트/팬영상컨텐츠추천사연있어요
1
01-15
1
수다
한정판 따구니 뱃지 [5]
소문남
01-15
2
01-15
1
수다
잔다 [3]
그루치
01-15
1
수다
10위권 진입이다 이마리야! [5]
비싸기만함
01-15
2
수다
오늘은 좀 다른거 [2]
탈모우라_발모도르수상
01-15
3
트수타그램
컵!!!안경닦이!!!컵받침!!!뱃지!!! [5]
뒹굴_싴크한싴
01-14
1
01-14
2
01-14
3
01-14
2
01-14
1
수다
결국엔... [1]
탈모우라_발모도르수상
01-14
1
01-14
1
01-14
2
01-14
3
수다
자 자 월요일이니까 [3]
그루치
01-14
2
수다
부산갔다 왔더니?! [5]
파스타리안__로케
01-14
1
수다
따찌방종각세우길레 [4]
비싸기만함
01-14
1
수다
따흐찌 에디션이 도착 [3]
그루치
01-13
0
01-13
1
트수타그램
왔다왔어 드디어 왔어 [6]
숨쉬는사람들
01-12
4
01-12
인기글 글 쓰기