Hi! I have problem with this exercise: http://www.spoj.com/problems/FLAMASTE/
I have the same output as in the example(so it seems like my program is working correctly) but Spoj's judge says that my answer is incorrect
I don't get what can be wrong.. Here is my code:
#include <iostream>
using namespace std;
int liczba_testow,licznik=1,dlugosc;
string wyraz;
int main()
{
cin >> liczba_testow; // how many words you want to cut
for ( int i = 0 ; i < liczba_testow ; i++ ) // loop for putting words
{
cin >> wyraz ; // input word
licznik = 1 ; // counter of the same characters
dlugosc = wyraz.length(); // checks the length of the word
for (int j=0;j<dlugosc;j++) // loop going trough every character of the word
{
if ( wyraz[j] != wyraz[j+1] and licznik < 2 ) // if character is NOT equal to the next character and counter is lower than 2
{
cout << wyraz[j]; // cout character
}
else if ( wyraz[j] != wyraz[j+1] and licznik > 2) // if character is NOT equal to next character and counter is bigger than 2
{
cout << wyraz[j] << licznik; // cout character and cout counter
licznik=1; // set counter at 1
}
else if ( wyraz[j] != wyraz[j+1] and licznik == 2) // if character is NOT equal to next character and counter is equal to 2
{
cout << wyraz[j-1] << wyraz[j]; // cout previous character and cout current character
licznik=1; // set counter at 1
}
else if ( wyraz[j] == wyraz[j+1] ) // if character IS equal to next character
{
licznik++; //incrementation of counter
}
}
}
return 0;
}
example INPUT:
4
OPSS
ABCDEF
ABBCCCDDDDEEEEEFGGHIIJKKKL
AAAAAAAAAABBBBBBBBBBBBBBBB
example OUTPUT:
OPSS
ABCDEF
ABBC3D4E5FGGHIIJK3L
A10B16