Page 4 of 4

Re: 11220 - Decoding the message

Posted: Wed Jan 15, 2014 12:13 am
by brianfry713
Doesn't match the sample I/O

Re: 11220 - Decoding the message

Posted: Mon Mar 10, 2014 1:09 pm
by uDebug
Shihab wrote:WA help
Look into the C++ function "getline" instead of using the deprecated function "gets". It's probably worth learning about.

Re: 11220 - Decoding the message

Posted: Sat Aug 23, 2014 8:53 pm
by Shahidul.CSE
I am getting RTE, but I don't understand why. Please, help me. Whats wrong with my code?

Code: Select all

Removed getting AC
:D :D

Re: 11220 - Decoding the message

Posted: Sun Aug 24, 2014 12:53 pm
by lighted
Jan wrote:Read the description again...
each line is composed by 1 ? M ? 30 words. Two words in the same line are separated by one or more white spaces. A word is formed by the letters A-Z and a-z and has at most 30 letters
So, 30*30 = 900 letters and with some white spaces you have almost 1000 characters in a line. But you have only 109 characters. For safety take 2000 or more.

Hope it helps.
Increase array limit to

Code: Select all

char words_in_lines[1000];

Re: 11220 - Decoding the message

Posted: Sun Aug 24, 2014 4:49 pm
by Shahidul.CSE
thanks, got accepted. :D :D

11220 - Decoding the message.

Posted: Sat Dec 06, 2014 7:04 pm
by mjimaz
I keep getting WA and I could not find anything wrong with my code!

REMOVED after AC.

Issue: New line between cases!

Re: 11220 - Decoding the message.

Posted: Sun Dec 07, 2014 3:30 pm
by lighted
Use code tags. Change input parsing. Print a blank line between each test case.

Re: 11220 - Decoding the message.

Posted: Sun Dec 07, 2014 4:55 pm
by mjimaz
Thanks lighted.

Re: 11220 - Decoding the message.

Posted: Fri Jan 08, 2016 8:43 am
by saniatrasel
I keep getting WA and I could not find anything wrong with my code!

Code: Select all

#include<stdio.h>
#include<string.h>
#define LINE 102
#define SIZE 100
int Ans;
char DecodeMessage[100001];
char Message[LINE][SIZE];
int k = 0;
int testCase;
int stringLength(char str[])
{
	int len;
	for (len = 0; str[len]; len++);
	return len;
}

bool isChar(char ch)
{
	if (ch >= 'A' && ch <= 'Z')
		return true;
	if (ch >= 'a' && ch <= 'z')
		return true;
	return false;
}

void solve(int lineNo)
{
	int i;
	int len = stringLength(Message[lineNo]);
	int j = 0;
	int wordCount = -1;
	
	int n = 0;
	for (i = 0; i < len; i++)
	{
		while(isChar(Message[lineNo][j]))
		{
			j++;
			n++;
		}		
		wordCount++;
		if (n > wordCount)
		{
			n = j - n + wordCount;
			DecodeMessage[k] = Message[lineNo][n];
			k++;
		}
		else
			wordCount--;
		
		n = 0;
		j++;
		if (j > len)
			break;
	}

	DecodeMessage[k] = '\0';
	DecodeMessage[k++] = '\n';
}

void printCase()
{
	if (testCase == 1)
		printf("Case #%d:", testCase);
	else
		printf("\nCase #%d:", testCase);
	printf("\n%s",DecodeMessage);
	testCase++;
}


void resetArr(char str[])
{
	memset(str,0x00,sizeof(str));
}

int main()
{
	//freopen("Text.txt", "r", stdin);
	//freopen("Text1.txt", "w", stdout);
	int T;
	scanf("%d", &T);
	int i = 0;
	k = 0;
	testCase = 1;
	int const_value = 0;
	while (1)
	{
		gets(Message[i]);
		int messageLength = stringLength(Message[i]);
		int DecodeLength = stringLength(DecodeMessage);

		if (messageLength == 0 && DecodeLength == 0)
		{
			const_value++;
			if (const_value < 10)
			{
				continue;
			}			
			const_value = 0;
		}
		
		if (Message[i][0] == '\0')
		{
			T--;
			
			int j;
			for (j = 0; j < i; j++)
				resetArr(Message[j]);
			i = 0;
			k = 0;
			printCase();
			int len = stringLength(DecodeMessage);
			for (i = 0; i < len; i++)
				DecodeMessage[i] = '\0';
			if (T == 0)
				break;
		}
		else
		{
			solve(i);
			i++;
		}
	}
	return 0;
}
Is there any special input that I am missing?

Thanks/
Saniat

Re[saniatrasel]: 11220 - Decoding the message.

Posted: Wed Mar 23, 2016 2:07 pm
by samir_h
Hello Saniat,

#1# Input Case #
How about handling below case:

Input:
1

1,234 1*23 12345 12345 123 1234 1234 12 123 1234 1234


Output:
Case #1:
1*34


I checked in uDebug and it seems it accepts numerical digits although in the problem description it said "A word is formed by the letters A-Z and a-z and has at most 30 letters."


#2# Boundary #
You are reading one line with gets(Message);
Message is of length 100. So what if the input line is: 12[100 Spaces]2[100 spaces]564