Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "student.h"
- #include <bits/stdc++.h>
- using namespace std;
- void encode(int N, int M[]) {
- for(int i = 0; i < N; i++)
- for(int j = 7; j >= 0; j--)
- if((M[i] >> j) % 2 == 1){
- send(8 * (i % 256) + 7 - j);
- if(i > 255)
- send(8 * (i % 256) + 7 - j);
- }
- }
- //------------------- DO NOT REMOVE NOR EDIT THESE 3 LINES -----------------
- //------------------- above is encode, below is decode ---------------------
- //--------------------cut here----------------------------------------------
- void decode(int N, int L, int X[]) {
- int cnt[512];
- for(int i = 0; i < 512; i++)
- cnt[i] = 0;
- for(int i = 0; i < L; i++){
- cnt[X[i]]++;
- if(cnt[X[i]] > 1){
- cnt[X[i]] -= 2;
- cnt[X[i] + 256] = 1;
- }
- }
- int msg = 0;
- for(int i = 0; i < 8 * N; i++){
- msg += cnt[i];
- if(i % 8 == 7){
- output(msg);
- msg = 0;
- continue;
- }
- msg *= 2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement