When I input t, I get a output of 0 first.
Then I am asked to enter the strings 2 times as there are 2 test cases.
The program takes strings as input. These strings is a sequence of + and -. the sequence is called chain if each two neighboring symbols of sequence are either '-+' or '+-'.
calculate the minimum number of symbols he need to replace (ex. '-' to '+' or '+' to '-') to receive a Chain sequence.
and output contains that minimum number.
Why am I getting a output of 0? I want to get rid of it.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int t;
cin >> t;
t++;
while(t--)
{
constlong k = pow(10,5);
char input[k];
cin.getline(input,k);
int count = 0;
if (input[0] == '+')
{
for (int i = 2; i < k; i = i + 2)
{
if (input[i] == '-')
{
count++;
}
}
for (int i = 1; i < k; i = i + 2)
{
if (input[i] == '+')
{
count++;
}
}
}
elseif (input[0] == '-')
{
for (int i = 2; i < k; i = i + 2)
{
if (input[i] == '+')
{
count++;
}
}
for (int i = 1; i < k; i = i + 2)
{
if (input[i] == '-')
{
count++;
}
}
}
cout << count << endl;
}
}