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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

class dataset
{
public:
	string line;
	int r, c;
	vector<vector<int>> 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<dataset> set;
	set.resize(numSet);
	
	vector<string> 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.
Topic archived. No new replies allowed.