-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc
94 lines (91 loc) · 1.78 KB
/
c
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
//난쟁이
//다른 사람
#include<cstdio>
#include<algorithm>
using namespace std;
int a[9];
int main() {
for (int i = 0; i < 9; i++) scanf("%d", &a[i]);
sort(a, a + 9);
while (next_permutation(a, a + 9)) { //조합 next_permutation(,)
int sum = 0;
for (int i = 0; i < 7; i++) sum += a[i];
if (sum == 100) {
for (int i = 0; i < 7; i++) printf("%d\n", a[i]);
break;
}
}
}
//조합 안 쓴
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n=9;
int num;
int sum=0;
vector<int> vec;
while(n-->0){
cin>>num;
vec.push_back(num);
sum+=num;
}
sort(vec.begin(), vec.end());
for(int i=0;i<8;i++)
{
for(int j=i+1;j<9;j++)
{
if(sum-vec[i]-vec[j]==100)
{
for(int k=0;k<9;k++)
{
if(k!=i&&k!=j)
cout<<vec[k]<<'\n';
}
return 0;
}
}
}
}
//
#include<iostream>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;
int main() {
int n;
int sum=0;
string str;
cin>>n;
cin>>str;
for(int i=0;i<n;i++){
sum+=(int)str[i]-(int)'0'; //char -> int or (C) scanf("%1d",&a);
}
cout<<sum;
return 0;
}
//string -> int 변환 : atoi(str.c_str());
//
#include <string>
#include <iostream>
#include<algorithm>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,a,b;
vector<pair<int,int>> v;
cin>>n;
while(n-->0){
cin>>a>>b;
v.push_back({a,b});
}
vector<pair<int,int>>::iterator iter;
sort(v.begin(),v.end());
for(iter=v.begin();iter!=v.end();iter++)
cout<<iter->first<<" "<<iter->second<<'\n';
}