boj step 8 rework

This commit is contained in:
2024-03-14 16:31:19 +09:00
parent 91154a5af1
commit 2b3cfa9426
5 changed files with 113 additions and 0 deletions

View 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;
}

View 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;
}

View 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;
}

View 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;
}

4
zeta_cpp/run.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
if [ -z "$*" ]; then echo "No args"; exit 0; fi
g++ -std=c++17 $1
./a.out < stdin.txt