Re: 11220 - Decoding the message
Posted: Wed Jan 15, 2014 12:13 am
Doesn't match the sample I/O
Look into the C++ function "getline" instead of using the deprecated function "gets". It's probably worth learning about.Shihab wrote:WA help
Code: Select all
Removed getting AC
Increase array limit toJan wrote:Read the description again...
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.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
Hope it helps.
Code: Select all
char words_in_lines[1000];
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;
}