Skip to content

Commit 201215a

Browse files
candy-game finished
1 parent 6feca6d commit 201215a

File tree

2 files changed

+2
-23
lines changed

2 files changed

+2
-23
lines changed

3085_Candy_Game/a.out

-288 Bytes
Binary file not shown.

3085_Candy_Game/main.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int check_longest(char** table, const int table_size) {
1919
if (table[i][j] != current_color) {
2020
longest_len = (longest_len < current_len) ? current_len : longest_len;
2121
current_len = 1;
22+
current_color = table[i][j];
2223
continue;
2324
}
2425
++current_len;
@@ -33,13 +34,13 @@ int check_longest(char** table, const int table_size) {
3334
if (table[i][j] != current_color) {
3435
longest_len = (longest_len < current_len) ? current_len : longest_len;
3536
current_len = 1;
37+
current_color = table[i][j];
3638
continue;
3739
}
3840
++current_len;
3941
}
4042
longest_len = (longest_len < current_len) ? current_len : longest_len;
4143
}
42-
4344
return longest_len;
4445
}
4546

@@ -72,39 +73,23 @@ int main() {
7273
int n, longest_len = 1;
7374
cin >> n;
7475
char** table = new char*[n];
75-
76-
cout << "table created... at least\n";
7776

7877
for (int i = 0; i < n; ++i) {
7978
table[i] = new char[n];
8079
string temp_input;
8180
cin >> temp_input;
8281
for (int j = 0; j < n; ++j)
8382
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;
9083
}
9184

92-
cout << "input read\n";
93-
9485
for (int i = 0; i < n; ++i) {
9586
for (int j = 0; j < n; ++j) {
96-
print_current_loc(table, n, i, j);
9787
if (j != n-1)
9888
if (table[i][j] != table[i][j+1]) {
9989
char temp = table[i][j];
10090
table[i][j] = table[i][j+1];
10191
table[i][j+1] = temp;
102-
//DEBUG
103-
print_table(table, n);
104-
cout << "------jchange------\n";
10592
int max_len = check_longest(table, n);
106-
//DEBUG
107-
cout << max_len << '\n';
10893
longest_len = (longest_len < max_len) ? max_len : longest_len;
10994
temp = table[i][j];
11095
table[i][j] = table[i][j+1];
@@ -116,19 +101,13 @@ int main() {
116101
char temp = table[i][j];
117102
table[i][j] = table[i+1][j];
118103
table[i+1][j] = temp;
119-
//DEBUG
120-
print_table(table, n);
121-
cout << "------ichange------\n";
122104
int max_len = check_longest(table, n);
123-
//DEBUG
124-
cout << max_len << '\n';
125105
longest_len = (longest_len < max_len) ? max_len : longest_len;
126106
temp = table[i][j];
127107
table[i][j] = table[i+1][j];
128108
table[i+1][j] = temp;
129109

130110
}
131-
cout << "====== Good ======\n";
132111
}
133112
}
134113

0 commit comments

Comments
 (0)