#include "encoder.h"
#include "decoder.h"
#include "encoderlib.h"
#include "decoderlib.h"
#include <stdio.h>
#include <stdlib.h>
/*
#define MAX_N 1000
#define MAX_L 10000
#define CHANNEL_RANGE 65535
#define MAX_EXPANSION 10
static int message[MAX_N];
static int N; // NN;
static int encoded_message[MAX_L];
static int L;
static int output_message[MAX_N];
static int O;
inline
void my_assert(int e){ if (!e) abort(); };
void send(int a)
{
if(L == MAX_L) {
printf("Encoded message too long.\n");
exit(0);
}
encoded_message[L] = a;
L++;
}
void output(int b)
{
if(O == N)
O++;
if(O > N)
return;
output_message[O] = b;
O++;
}
static void shuffle()
{
int t,i;
i=0;
while(i < L-1) {
t = encoded_message[i];
encoded_message[i] = encoded_message[i+1];
encoded_message[i+1] = t;
i += 2;
}
}
static void check_encoded_message()
{
int i;
if(L > MAX_EXPANSION * N) {
printf("Encoded message too long.");
exit(0);
}
for(i=0; i < L; i++)
if((encoded_message[i] < 0) ||
(encoded_message[i] > CHANNEL_RANGE)) {
printf("Bad encoded integer.\n");
exit(0);
}
}
static int check_output()
{
int i;
if(O!=N)
return 0;
for(i = 0; i < N; i++)
if(message[i] != output_message[i])
return 0;
return 1;
}
*/
void send(int a);
//void output(int b);
void encode(int N, int M[])
{
int i,cont1,cont0;
for(i=0; i<N; i++){
for(int j=0;j<8;j++){
if(M[i]&(1<<j)){
send(8*i+j);
}
}
}
}
/*
void decode(int N, int L, int X[])
{
int i, b,ans[100],pos1,pos2;
for(int i=0;i<100;i++)ans[i]=0;
for(i=0; i<L; i++) {
pos1=X[i]/8;
pos2=X[i]%8;
ans[pos1]+=(1<<pos2);
}
for(int i=0;i<N;i++){
output(ans[i]);
}
}
*/
/*
int main()
{
int i,t;
double ratio;
my_assert(1==scanf("%d",&N));
for(i = 0; i < N; i++)
my_assert(1==scanf("%d",&message[i]));
ratio = 0;
for(t=0; t<2; t++) {
L = 0;
encode(N,message);
check_encoded_message();
if((double) L / N > ratio)
ratio = ((double)L)/N;
if(t==1)
shuffle();
// NN = 0;
O = 0;
decode(N,L,encoded_message);
if(!check_output()) {
printf("Incorrect.\n");
exit(0);
}
}
printf("Correct.\n");
fprintf(stderr,"Ratio = %3.3f\n",ratio);
return 0;
}*/
#include "encoder.h"
#include "decoder.h"
#include "encoderlib.h"
#include "decoderlib.h"
#include <stdio.h>
#include <stdlib.h>
/*
#define MAX_N 1000
#define MAX_L 10000
#define CHANNEL_RANGE 65535
#define MAX_EXPANSION 10
static int message[MAX_N];
static int N; // NN;
static int encoded_message[MAX_L];
static int L;
static int output_message[MAX_N];
static int O;
inline
void my_assert(int e){ if (!e) abort(); };
void send(int a)
{
if(L == MAX_L) {
printf("Encoded message too long.\n");
exit(0);
}
encoded_message[L] = a;
L++;
}
void output(int b)
{
if(O == N)
O++;
if(O > N)
return;
output_message[O] = b;
O++;
}
static void shuffle()
{
int t,i;
i=0;
while(i < L-1) {
t = encoded_message[i];
encoded_message[i] = encoded_message[i+1];
encoded_message[i+1] = t;
i += 2;
}
}
static void check_encoded_message()
{
int i;
if(L > MAX_EXPANSION * N) {
printf("Encoded message too long.");
exit(0);
}
for(i=0; i < L; i++)
if((encoded_message[i] < 0) ||
(encoded_message[i] > CHANNEL_RANGE)) {
printf("Bad encoded integer.\n");
exit(0);
}
}
static int check_output()
{
int i;
if(O!=N)
return 0;
for(i = 0; i < N; i++)
if(message[i] != output_message[i])
return 0;
return 1;
}
*/
//void send(int a);
void output(int b);
/*
void encode(int N, int M[])
{
int i,cont1,cont0;
for(i=0; i<N; i++){
for(int j=0;j<8;j++){
if(M[i]&(1<<j)){
send(8*i+j);
}
}
}
}
*/
void decode(int N, int L, int X[])
{
int i, b,ans[100],pos1,pos2;
for(int i=0;i<100;i++)ans[i]=0;
for(i=0; i<L; i++) {
pos1=X[i]/8;
pos2=X[i]%8;
ans[pos1]+=(1<<pos2);
}
for(int i=0;i<N;i++){
output(ans[i]);
}
}
/*
int main()
{
int i,t;
double ratio;
my_assert(1==scanf("%d",&N));
for(i = 0; i < N; i++)
my_assert(1==scanf("%d",&message[i]));
ratio = 0;
for(t=0; t<2; t++) {
L = 0;
encode(N,message);
check_encoded_message();
if((double) L / N > ratio)
ratio = ((double)L)/N;
if(t==1)
shuffle();
// NN = 0;
O = 0;
decode(N,L,encoded_message);
if(!check_output()) {
printf("Incorrect.\n");
exit(0);
}
}
printf("Correct.\n");
fprintf(stderr,"Ratio = %3.3f\n",ratio);
return 0;
}*/
Compilation message
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:88:9: warning: unused variable 'cont1' [-Wunused-variable]
int i,cont1,cont0;
^~~~~
encoder.cpp:88:15: warning: unused variable 'cont0' [-Wunused-variable]
int i,cont1,cont0;
^~~~~
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:101:12: warning: unused variable 'b' [-Wunused-variable]
int i, b,ans[100],pos1,pos2;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1520 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
5 ms |
1520 KB |
Output is correct |
4 |
Correct |
5 ms |
1520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1520 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
5 ms |
1520 KB |
Output is correct |
4 |
Correct |
5 ms |
1520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1784 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
5 ms |
1520 KB |
Output is correct |
4 |
Correct |
6 ms |
1520 KB |
Output is correct |
5 |
Correct |
6 ms |
1520 KB |
Output is correct |
6 |
Correct |
7 ms |
1576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
5 ms |
1528 KB |
Output is partially correct - P = 8.000000 |
2 |
Partially correct |
7 ms |
1520 KB |
Output is partially correct - P = 8.000000 |
3 |
Incorrect |
4 ms |
776 KB |
Error : Bad encoded integer |
4 |
Incorrect |
4 ms |
764 KB |
Error : Bad encoded integer |
5 |
Incorrect |
4 ms |
780 KB |
Error : Bad encoded integer |
6 |
Incorrect |
4 ms |
1012 KB |
Error : Bad encoded integer |
7 |
Incorrect |
4 ms |
856 KB |
Error : Bad encoded integer |