Skip to content

Instantly share code, notes, and snippets.

@kawaii-ghost
Last active May 15, 2023 04:15
Show Gist options
  • Save kawaii-ghost/b97c937d9ad938045dcc820e286964fa to your computer and use it in GitHub Desktop.
Save kawaii-ghost/b97c937d9ad938045dcc820e286964fa to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <format>
int main() {
std::ios_base::sync_with_stdio(false);
std::cout << "Irrashai, inputnya dipisah spasi ya ~ " << std::endl;
std::cout << "Maksimum 255 bilangan bulat positif rentang 1 <= 255" << std::endl;
std::cout << "Masukkan input : ";
size_t total;
std::array<int, 256> arr = {0};
for (size_t i = 1; i <= 255; i++) {
std::cin >> arr[i];
char ch = std::cin.get();
if (ch == EOF || ch == '\n') {
total = i;
break;
}
}
std::sort(&arr[1], &arr[total]);
std::array<int, 256> res = {0};
for (size_t i = 1; i <= total; i++){
res[arr[i]]++;
}
std::cout << "---------" << std::endl;
for (size_t i = 1; i <= 255; i++) {
if (res[i]) {
std::cout << '|';
if (res[i] <= 9) {
std::cout << " ";
} else if (res[i] <= 99) {
std::cout << " ";
}
std::cout << std::format("{}|", i};
if (i <= 9) {
std::cout << " ";
} else if (i <= 99) {
std::cout << " ";
}
std::cout << std::format("{}|", res[i]) << std::endl;
}
}
std::cout << "---------" << std::endl;
std::cout << std::format("Total : {}", total) << std::endl;
std::cout << std::format("Min : {}", arr[1]) << std::endl;
std::cout << std::format("Max : {}", arr[total]) << std::endl;
int range = arr[total] - arr[1];
std::cout << "Range : " << range << std::endl;
float kelas = 1.0 + 3.3 * log(total);
std::cout << "Kelas : " << kelas << std::endl;
float interval = range / kelas;
std::cout << "Interval : " << interval << " (" << round(interval) << ')' << std::endl;
std::cout << "------------" << std::endl;
for (size_t i = arr[1]; i <= arr[total];) {
std::cout << '|';
if (res[i] <= 9) {
std::cout << " ";
} else if (res[i] <= 99) {
std::cout << " ";
}
std::cout << i << '-';
i += interval;
if (i <= 9) {
std::cout << " ";
} else if (i <= 99) {
std::cout << " ";
}
std::cout << i << '|' << std::endl;
int tot = 0;
for (int x = i - interval; x < i; i++) {
tot += res[x];
}
if (tot <= 9) {
std::cout << " ";
} else if (tot <= 99) {
std::cout << " ";
}
std::cout << tot << '|' << std::endl;
}
std::cout << "------------" << std::endl;
return 0;
}
@kawaii-ghost
Copy link
Author

Sucksss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment