I am trying to solve a CodeChef problem. Whenever I run it I get a segmentation fault. This is the link to the problem: Malvika is peculiar about color of balloons
Here is my code :
#include<iostream>
#include<cstring>
#include<algorithm>
int main(){
std::string balloonColors;
size_t numberOfAmber;
size_t numberOfBrass;
int t;
int results[t];
std::cin >> t;
for (int i = 0; i < t; i++){
int result = 0;
std::cin >> balloonColors;
numberOfAmber = std::count(balloonColors.begin(), balloonColors.end(), 'a');
numberOfBrass = std::count(balloonColors.begin(), balloonColors.end(), 'b');
if (numberOfAmber == 0 || numberOfBrass == 0){
result = 0;
}
if (numberOfAmber <= numberOfBrass){
result = (int)numberOfAmber;
}
else {
result = (int)numberOfBrass;
}
results[i] = result;
}
for (int x = 0; x < t; x++){
std::cout << results[x] << std::endl;
}
}