boj step 8 rework
This commit is contained in:
41
zeta_cpp/completed/11005.cpp
Normal file
41
zeta_cpp/completed/11005.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
char translate(int c) {
|
||||
if (0 <= c && c <= 9) {
|
||||
return 48 + c;
|
||||
} else {
|
||||
return 55 + c;
|
||||
}
|
||||
}
|
||||
|
||||
vector<char> calculate(int N, int B) {
|
||||
vector<int> S(0);
|
||||
while (N >= B) {
|
||||
S.push_back(N % B);
|
||||
N /= B;
|
||||
|
||||
}
|
||||
S.push_back(N % B);
|
||||
reverse(S.begin(), S.end());
|
||||
vector<char> ST(0);
|
||||
for(auto i: S) {
|
||||
ST.push_back(translate(i));
|
||||
}
|
||||
return ST;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
int B;
|
||||
cin >> N >> B;
|
||||
vector<char> s = calculate(N, B);
|
||||
for(auto i: s) {
|
||||
cout << i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
29
zeta_cpp/completed/2720.cpp
Normal file
29
zeta_cpp/completed/2720.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void solve(int x, int c[], int cat[]) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
c[i] = (x / cat[i]);
|
||||
x %= cat[i];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int cat[4] = {25, 10, 5, 1};
|
||||
|
||||
int N;
|
||||
|
||||
cin >> N;
|
||||
for (int i = 0; i < N; i++) {
|
||||
int x;
|
||||
int coins[4];
|
||||
cin >> x;
|
||||
solve(x, coins, cat);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
cout << coins[j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
30
zeta_cpp/completed/2745.cpp
Normal file
30
zeta_cpp/completed/2745.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int translate(char c) {
|
||||
if (48 <= c && c <= 57) {
|
||||
return c - 48;
|
||||
} else {
|
||||
return c - 55;
|
||||
}
|
||||
}
|
||||
|
||||
int calculate(string s, int n) {
|
||||
int l = s.length();
|
||||
int r = 0;
|
||||
for (int i = 0; i < l; i++) {
|
||||
r += translate(s[i]) * pow(n, l - i - 1);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
string s;
|
||||
int n;
|
||||
cin >> s >> n;
|
||||
cout << calculate(s, n);
|
||||
return 0;
|
||||
}
|
||||
9
zeta_cpp/completed/2903.cpp
Normal file
9
zeta_cpp/completed/2903.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
std::cin >> n;
|
||||
std::cout << (int) pow(((1 << n) + 1), 2);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user