11220 - Decoding the message.

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11220 - Decoding the message

Post by brianfry713 » Wed Jan 15, 2014 12:13 am

Doesn't match the sample I/O
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11220 - Decoding the message

Post by uDebug » Mon Mar 10, 2014 1:09 pm

Shihab wrote:WA help
Look into the C++ function "getline" instead of using the deprecated function "gets". It's probably worth learning about.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11220 - Decoding the message

Post by Shahidul.CSE » Sat Aug 23, 2014 8:53 pm

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
Last edited by Shahidul.CSE on Sun Aug 24, 2014 4:54 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11220 - Decoding the message

Post by lighted » Sun Aug 24, 2014 12:53 pm

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];
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11220 - Decoding the message

Post by Shahidul.CSE » Sun Aug 24, 2014 4:49 pm

thanks, got accepted. :D :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

mjimaz
New poster
Posts: 6
Joined: Thu Jan 09, 2014 1:03 am

11220 - Decoding the message.

Post by mjimaz » Sat Dec 06, 2014 7:04 pm

I keep getting WA and I could not find anything wrong with my code!

REMOVED after AC.

Issue: New line between cases!
Last edited by mjimaz on Sun Dec 07, 2014 4:56 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11220 - Decoding the message.

Post by lighted » Sun Dec 07, 2014 3:30 pm

Use code tags. Change input parsing. Print a blank line between each test case.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mjimaz
New poster
Posts: 6
Joined: Thu Jan 09, 2014 1:03 am

Re: 11220 - Decoding the message.

Post by mjimaz » Sun Dec 07, 2014 4:55 pm

Thanks lighted.

saniatrasel
New poster
Posts: 5
Joined: Tue Apr 07, 2015 11:10 am

Re: 11220 - Decoding the message.

Post by saniatrasel » Fri Jan 08, 2016 8:43 am

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

samir_h
New poster
Posts: 11
Joined: Wed Mar 18, 2015 8:47 am

Re[saniatrasel]: 11220 - Decoding the message.

Post by samir_h » Wed Mar 23, 2016 2:07 pm

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

Post Reply

Return to “Volume 112 (11200-11299)”