GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Failure even though expected result is correct

Hi,

I'm trying to submit a piece of code forthe Good String problem. The thing is, although my code runs well for the expected results, when I submit it it fails in the test case  "fghijkjihgfedcbcbcded"

I already went through the "Some common errors", applied the fixes but still getting the same failure.

Also, I tried working in GCC and VS2015, and it works correctly.

 

Could you give me a hand please?

 

This is the problem: http://www.practice.geeksforgeeks.org/problem-page.php?pid=1366

This is my code:

#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <stdlib.h> 

void countItoJThroughAlphabet(std::vector<std::string> vecS);

int main() {
	//code

	int T;
	std::cin >> T;
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

	int max = 0;
	std::vector<std::string> vecS;
	while (max < T)
	{
		std::string S;
		std::getline(std::cin, S);
		if (S.size() == 0)
			continue;
		if (S.size() > 50)
		{
			std::cout << "String must have length less than 50!" << std::endl;
			std::cout << "Enter another string" << std::endl;
			continue;
		}
		vecS.push_back(S);
		max++;
	}

	countItoJThroughAlphabet(vecS);

	return 0;
}


void countItoJThroughAlphabet(std::vector<std::string> vecS)
{
	std::vector<std::string>::iterator iterVecS = vecS.begin();
	while (iterVecS != vecS.end())
	{
		std::string cis = *iterVecS;
		std::string::iterator cisIt = cis.begin();
		int distance = 0;
		
		for (size_t i = 0; i < cis.size(); i++)
		{
			int c1 = *(cisIt + i);
			int c2 = 0;
			if ((cisIt + i) != cis.end() - 1)
				c2 = *(cisIt + (i + 1));
			else
				break;
			distance = abs(c1 - c2);
			if (distance != 1)
			{
				std::cout << "NO" << std::endl;
				break;
			}
				
		}
		if (distance == 1)
			std::cout << "YES" << std::endl;
		iterVecS++;
	}
}

 

asked Sep 10, 2016 by Mariojulio Zaldivar
...