### Problem with “GNY07D - Decoding”

Hello, I am trying to solve this problem on SPOJ. However, the judge is returning “runtime error (SIGABRT)”.

Can someone please tell me what’s wrong with my code? Thanks.

This is the problem: http://www.spoj.com/problems/GNY07D/

Here is my code:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153`` ``````#include #include #include #include using namespace std; class dataset { public: string line; int r, c; vector> data; }; //Converts binary to decimal char convBin(string binary) { int j = 4; int output = 0; for (int i = 0; i < 5; i++) { if (binary.at(j) - '0' == 1) { output += pow(2, i); } j--; } output += 64; if (output == 64) { return ' '; } else { return output; } } string convMat(dataset &set) { string output = ""; int val = 0; while (!set.data.empty()) { if (val == 0 && set.r != 0) { for (int i = 0; i < set.c; i++) { output += to_string(set.data.at(0).at(i)); } set.data.erase(set.data.begin()); set.r--; val++; } if (val == 1 && set.r != 0) { for (int i = 0; i < set.r; i++) { output += to_string(set.data.at(i).at(set.c - 1)); set.data.at(i).erase(set.data.at(i).begin() + (set.c - 1)); } set.c--; val++; } if (val == 2 && set.r != 0) { for (int i = (set.c - 1); i >= 0; i--) { output += to_string(set.data.at(set.r - 1).at(i)); } set.data.erase(set.data.begin() + (set.r - 1)); set.r--; val++; } if (val == 3 && set.r != 0) { for (int i = (set.r - 1); i >= 0; i--) { output += to_string(set.data.at(i).at(0)); set.data.at(i).erase(set.data.at(i).begin()); } set.c--; val = 0; } if (set.c == 0) { while (set.r > 0) { if (set.data.at(0).empty()) { set.data.erase(set.data.begin()); set.r--; } } } } return output; } //Inputs string into matrix format void inputMat(dataset &set) { cin >> set.r >> set.c >> set.line; set.data.resize(set.r); for (int i = 0; i < set.r; i++) { for (int j = 0; j < set.c; j++) { set.data.at(i).push_back(set.line.at(0) - '0'); set.line.erase(set.line.begin()); } } } //Main function int main() { int numSet; cin >> numSet; vector set; set.resize(numSet); vector out; for (int i = 0; i < numSet; i++) { inputMat(set.at(i)); string line = convMat(set.at(i)); int num = (line.length() - (line.length() % 5)) / 5; string text = ""; for (int j = 0; j < num; j++) { text += convBin(line.substr(0, 5)); line.erase(0, 5); } out.push_back(text); } for (int i = 0; i < numSet; i++) { cout << (i + 1) << " " << out.at(i) << endl; } return 0; }``````
Last edited on
Nevermind, I managed to solve the problem.
Registered users can post here. Sign in or register to post.