@@ -19,6 +19,7 @@ int check_longest(char** table, const int table_size) {
19
19
if (table[i][j] != current_color) {
20
20
longest_len = (longest_len < current_len) ? current_len : longest_len;
21
21
current_len = 1 ;
22
+ current_color = table[i][j];
22
23
continue ;
23
24
}
24
25
++current_len;
@@ -33,13 +34,13 @@ int check_longest(char** table, const int table_size) {
33
34
if (table[i][j] != current_color) {
34
35
longest_len = (longest_len < current_len) ? current_len : longest_len;
35
36
current_len = 1 ;
37
+ current_color = table[i][j];
36
38
continue ;
37
39
}
38
40
++current_len;
39
41
}
40
42
longest_len = (longest_len < current_len) ? current_len : longest_len;
41
43
}
42
-
43
44
return longest_len;
44
45
}
45
46
@@ -72,39 +73,23 @@ int main() {
72
73
int n, longest_len = 1 ;
73
74
cin >> n;
74
75
char ** table = new char *[n];
75
-
76
- cout << " table created... at least\n " ;
77
76
78
77
for (int i = 0 ; i < n; ++i) {
79
78
table[i] = new char [n];
80
79
string temp_input;
81
80
cin >> temp_input;
82
81
for (int j = 0 ; j < n; ++j)
83
82
table[i][j] = temp_input[j];
84
- // DEBUG
85
- cout << " The input string is: " << temp_input << endl;
86
- for (int j = 0 ; j < n; ++j) {
87
- cout << table[i][j] << ' ' ;
88
- }
89
- cout << endl;
90
83
}
91
84
92
- cout << " input read\n " ;
93
-
94
85
for (int i = 0 ; i < n; ++i) {
95
86
for (int j = 0 ; j < n; ++j) {
96
- print_current_loc (table, n, i, j);
97
87
if (j != n-1 )
98
88
if (table[i][j] != table[i][j+1 ]) {
99
89
char temp = table[i][j];
100
90
table[i][j] = table[i][j+1 ];
101
91
table[i][j+1 ] = temp;
102
- // DEBUG
103
- print_table (table, n);
104
- cout << " ------jchange------\n " ;
105
92
int max_len = check_longest (table, n);
106
- // DEBUG
107
- cout << max_len << ' \n ' ;
108
93
longest_len = (longest_len < max_len) ? max_len : longest_len;
109
94
temp = table[i][j];
110
95
table[i][j] = table[i][j+1 ];
@@ -116,19 +101,13 @@ int main() {
116
101
char temp = table[i][j];
117
102
table[i][j] = table[i+1 ][j];
118
103
table[i+1 ][j] = temp;
119
- // DEBUG
120
- print_table (table, n);
121
- cout << " ------ichange------\n " ;
122
104
int max_len = check_longest (table, n);
123
- // DEBUG
124
- cout << max_len << ' \n ' ;
125
105
longest_len = (longest_len < max_len) ? max_len : longest_len;
126
106
temp = table[i][j];
127
107
table[i][j] = table[i+1 ][j];
128
108
table[i+1 ][j] = temp;
129
109
130
110
}
131
- cout << " ====== Good ======\n " ;
132
111
}
133
112
}
134
113
0 commit comments