740 - Baudot Data Communication Code
Moderator: Board moderators
740 - Baudot Data Communication Code
Cam someone send me some crucial input cases? I
-
- Experienced poster
- Posts: 193
- Joined: Thu Sep 19, 2002 6:39 am
- Location: Indonesia
- Contact:
Code: Select all
switch (ind){
case 27: shift=(shift)?0:1;
break;
case 31: shift=(shift)?0:1;
break;
Code: Select all
case 27: shift = 0; break;
case 31: shift = 1; break;
In addition, don't forget to always initialize each message with shift = 0.
-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
740 SHIFT characters.
1. Space is referred to the SHIFT Characters.
However, does the sequence remain the same each time?
[ SPACE --- > SHIFT DOWN --- > SHIFT UP] ?
2. "It should be initiated as "DOWN" at first."
How about if there is a shift down afterwards ?
e.g. 1011010110[shift down characters here]1011010110
|________| |________|
| |
(DOWN) (DOWN)
Is it right ?
However, does the sequence remain the same each time?
[ SPACE --- > SHIFT DOWN --- > SHIFT UP] ?
2. "It should be initiated as "DOWN" at first."
How about if there is a shift down afterwards ?
e.g. 1011010110[shift down characters here]1011010110
|________| |________|
| |
(DOWN) (DOWN)
Is it right ?
-
- Experienced poster
- Posts: 193
- Joined: Thu Sep 19, 2002 6:39 am
- Location: Indonesia
- Contact:
1. Space (' ') is not a shift-character. In the input they will simply skip the character for 11011 and 11111, those are the codes for shifting down or up. Problem description stated that a shift condition will stay that way until you get another shift-code that says otherwise.
2. Whenever you find a shift-code, just blindly apply the suggested shift-condition. I got AC-ed that way.
-turuthok-
2. Whenever you find a shift-code, just blindly apply the suggested shift-condition. I got AC-ed that way.
-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
-
- New poster
- Posts: 9
- Joined: Wed Apr 16, 2003 6:50 pm
- Location: Braga, Portugal
- Contact:
hello.
i've been reading all the posts again and again and i still not know why my code gets WA.
can someone try to find some bug in my code? thanks
code:
[c]
#include <math.h>
char mensagem[80];
int sim;
char b1[32],b2[32];
int shift;
void inicializa()
{
int i;
for (i=0;i<80;i++)
{
mensagem=0;
}
}
void mostra_mensagem()
{
int i,j;
shift=0;
for (j=0;j<80&& mensagem[j];j+=5)
{
int b,ind=0,a;
for (a=j+4,b=0;a>=j;a--,b++)
{
ind=ind+(mensagem[a]-'0')*((int) pow(2,b));
}
switch (ind){
case 27: shift=0;break;
case 31: shift=1;break;
default:printf("%c",(!shift)?b1[ind]:b2[ind]);
}
}
}
int main()
{
int i;
sim=0;
scanf("%[^\n]",b1);
getchar();
scanf("%[^\n]",b2);
getchar();
while (scanf("%[^\n]",mensagem)>0)
{
shift=0;
getchar();
if (sim) printf("\n");
else sim=1;
mostra_mensagem();
inicializa();
}
}
[/c]
thanks for any help.
Vitor
i've been reading all the posts again and again and i still not know why my code gets WA.
can someone try to find some bug in my code? thanks
code:
[c]
#include <math.h>
char mensagem[80];
int sim;
char b1[32],b2[32];
int shift;
void inicializa()
{
int i;
for (i=0;i<80;i++)
{
mensagem=0;
}
}
void mostra_mensagem()
{
int i,j;
shift=0;
for (j=0;j<80&& mensagem[j];j+=5)
{
int b,ind=0,a;
for (a=j+4,b=0;a>=j;a--,b++)
{
ind=ind+(mensagem[a]-'0')*((int) pow(2,b));
}
switch (ind){
case 27: shift=0;break;
case 31: shift=1;break;
default:printf("%c",(!shift)?b1[ind]:b2[ind]);
}
}
}
int main()
{
int i;
sim=0;
scanf("%[^\n]",b1);
getchar();
scanf("%[^\n]",b2);
getchar();
while (scanf("%[^\n]",mensagem)>0)
{
shift=0;
getchar();
if (sim) printf("\n");
else sim=1;
mostra_mensagem();
inicializa();
}
}
[/c]
thanks for any help.
Vitor
-
- New poster
- Posts: 5
- Joined: Sun Feb 23, 2003 7:33 pm
help me~
Is there any special input for this problem?
I've tested many input data and got correct answer in my computer..
but still got a WA!
Can anyone take a look at my code??
thanks a lot~~
[c]
#include<stdio.h>
char table[2][33],str[200],*p;
int i,code[100],count;
void encode(void)
{
i=0;
while (code)
{
if (code==31)
{
while (code[++i]!=27 && code)
putchar(table[1][code]);
if (!code)
break;
i++;
}
putchar(table[0][code]);
i++;
}
putchar('\n');
}
void deal(void)
{
for (i=0;i<200;i++)
code=0;
count=-1;
p = & str;
while (*p)
{
code[++count]=16*(*p-48)+8*(*(++p)-48)+4*(*(++p)-48)+2*(*(++p)-48)+(*(++p)-48);
p++;
}
encode();
}
int main(void)
{
gets(table[0]);
gets(table[1]);
while ((gets(str))!=NULL)
deal();
return 0;
}
[/c]
I've tested many input data and got correct answer in my computer..
but still got a WA!
Can anyone take a look at my code??
thanks a lot~~
[c]
#include<stdio.h>
char table[2][33],str[200],*p;
int i,code[100],count;
void encode(void)
{
i=0;
while (code)
{
if (code==31)
{
while (code[++i]!=27 && code)
putchar(table[1][code]);
if (!code)
break;
i++;
}
putchar(table[0][code]);
i++;
}
putchar('\n');
}
void deal(void)
{
for (i=0;i<200;i++)
code=0;
count=-1;
p = & str;
while (*p)
{
code[++count]=16*(*p-48)+8*(*(++p)-48)+4*(*(++p)-48)+2*(*(++p)-48)+(*(++p)-48);
p++;
}
encode();
}
int main(void)
{
gets(table[0]);
gets(table[1]);
while ((gets(str))!=NULL)
deal();
return 0;
}
[/c]
740_WA_HLP_PLS_MY..CODE
Any critical inputs? I cant find the problem.
Are the first two lines for only first time input ?
HELP ME................
==============================
#include<stdio.h>
#include<math.h>
int main()
{
char d_sft[32], u_sft[32];
char code[100];
long i, j, k, flag, a, val, p;
gets(d_sft);
gets(u_sft);
while(gets(code))
{
i = 0; k = 5; flag = 0;
while(code != '\0')
{
val = 0;
for(p = 4; i < k; i++, p--)
{
a = pow(2, p);
a = a*(code-48);
val += a;
}
k += 5;
if(flag == 0)
{
if(val != 4 && val == 31)
flag = 1;
else printf("%c", d_sft[val]);
}
else if(flag == 1)
{
if(val != 4 && (val == 27))
flag = 0;
else printf("%c", u_sft[val]);
}
}
printf("\n");
}
return 0;
}
============================
Are the first two lines for only first time input ?
HELP ME................

==============================
#include<stdio.h>
#include<math.h>
int main()
{
char d_sft[32], u_sft[32];
char code[100];
long i, j, k, flag, a, val, p;
gets(d_sft);
gets(u_sft);
while(gets(code))
{
i = 0; k = 5; flag = 0;
while(code != '\0')
{
val = 0;
for(p = 4; i < k; i++, p--)
{
a = pow(2, p);
a = a*(code-48);
val += a;
}
k += 5;
if(flag == 0)
{
if(val != 4 && val == 31)
flag = 1;
else printf("%c", d_sft[val]);
}
else if(flag == 1)
{
if(val != 4 && (val == 27))
flag = 0;
else printf("%c", u_sft[val]);
}
}
printf("\n");
}
return 0;
}
============================
AkHtEr