Skip to content

Instantly share code, notes, and snippets.

@cbdavide
Created January 25, 2019 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbdavide/166a96b440ada710e292bbd0f5fda146 to your computer and use it in GitHub Desktop.
Save cbdavide/166a96b440ada710e292bbd0f5fda146 to your computer and use it in GitHub Desktop.
UVa 128 - Software CRC
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int MOD = 34943;
const int oo = ~(1<<31);
void load(int c, int &num) {
num <<= 8;
num += c;
num %= MOD;
}
string clean(int n) {
string num;
stringstream s;
s << hex << n;
num = s.str();
while(num.size() < 4)
num = "0" + num;
for(char &c : num) c = toupper(c);
num.insert(2, " ");
return num;
}
int main() {
#ifndef CBDAVIDES
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif
int nm;
string line;
while(getline(cin, line) && line != "#") {
int num = 0;
for(char c : line)
load(c, num);
num = ((ll)num << 16) % MOD;
cout << clean((MOD - num) % MOD) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment