Sum
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
ll N;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>N;
ll ans = 1ll*(N*(N+1))/2;
cout<<ans;
return 0;
}
List
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int N;
list <int> ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>N;
if(N==1){
cout<<1;
return 0;
}
if(N<4){
cout<<"NO SOLUTION";
return 0;
}
ans.push_back(2);
ans.push_back(4);
ans.push_back(1);
ans.push_back(3);
ans.push_back(5);
for(int i=6;i<=N;i++){
if(i%2==0){
ans.push_front(i);
}else{
ans.push_back(i);
}
}
list<int>::iterator it;
for(auto it=ans.begin();it!=ans.end();it++){
cout<<*it<<" ";
}
return 0;
}
Palindrome
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int alphabet[26];
string al;
int chk;
list <char> solf,solm,solb;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>al;
for(int i=0;i<al.size();i++){
alphabet[al[i]-'A']++;
}
for(int j=0;j<26;j++){
char a = j+'A';
if(chk>=2){
cout<<"NO SOLUTION";
return 0;
}
int temp = alphabet[j]%2;
int f = alphabet[j]/2;
if(temp==0){
for(int i=0;i<f;i++){
solf.push_back(a);
solb.push_front(a);
}
}else{
for(int i=0;i<f;i++){
solf.push_back(a);
solb.push_front(a);
}
solm.push_back(a);
chk++;
}
}
for(auto it=solf.begin();it!=solf.end();it++){
cout<<*it;
}
for(auto it=solm.begin();it!=solm.end();it++){
cout<<*it;
}
for(auto it=solb.begin();it!=solb.end();it++){
cout<<*it;
}
return 0;
}
Pinot
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int N;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin>>N;
for(ll i=0,a,b;i<N;i++){
cin>>a>>b;
if(a>2*b||b>2*a) cout<<"NO"<<"\n";
else if((a+b)%3==0) cout<<"YES"<<"\n";
else cout<<"NO"<<"\n";
}
return 0;
}
'개발자 > algorithm' 카테고리의 다른 글
1 - Programming languages, Working with numbers (0) | 2020.07.21 |
---|---|
백준 16918번 : 봄버맨 (c++) (0) | 2020.07.10 |
CSES : Missing Number (c++) (0) | 2020.06.14 |
CSES : Weird Algorithm (c++) (0) | 2020.06.14 |
백준 1969번 : DNA (c++) (0) | 2020.06.14 |