Upload files to "/"
This commit is contained in:
commit
03f4a41580
@ -0,0 +1,50 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// Fungsi untuk mengkonversi hex ke desimal
|
||||||
|
int hexToDec(const string& hexCode) {
|
||||||
|
int decimalValue;
|
||||||
|
stringstream ss;
|
||||||
|
ss << hex << hexCode;
|
||||||
|
ss >> decimalValue;
|
||||||
|
return decimalValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fungsi utama untuk mencari warna dominan
|
||||||
|
char findDominantColor(const vector<string>& colorCodes) {
|
||||||
|
int R = 0, G = 0, B = 0;
|
||||||
|
|
||||||
|
// Iterasi melalui daftar warna
|
||||||
|
for (const string& code : colorCodes) {
|
||||||
|
if (code.size() == 6) { // Pastikan format HEX benar
|
||||||
|
R += hexToDec(code.substr(0, 2));
|
||||||
|
G += hexToDec(code.substr(2, 2));
|
||||||
|
B += hexToDec(code.substr(4, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Menentukan warna dominan
|
||||||
|
if (R > G && R > B) return 'R';
|
||||||
|
else if (G > R && G > B) return 'G';
|
||||||
|
else if (B > R && B > G) return 'B';
|
||||||
|
else return 'X'; // Jika tidak ada warna dominan
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
vector<string> colorCodes = {
|
||||||
|
"004455", "3321FE", "EE6633",
|
||||||
|
"A07689", "550055", "333333",
|
||||||
|
"333333", "444444", "555555",
|
||||||
|
"980000", "DD0000", "FE5689",
|
||||||
|
"000000", "00A900", "0CC000"
|
||||||
|
};
|
||||||
|
|
||||||
|
char dominantColor = findDominantColor(colorCodes);
|
||||||
|
cout << "Warna Dominan: " << dominantColor << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user