c - What's wrong with my algorithm code? -


The question I am trying to solve is:

Rectangular cake, represented as an R × C grid. Each cell has a bad strawberry, or is empty. For example, a 3 × 4 cake can look like this:

The cacinninator is eating cakes! Every time he eats, he chooses a line or a column that does not contain any of the worst strawberries and contains at least one cake cell that is not eaten before, and all the cakes eat the cells there. He can decide to eat at any time.

Please produce the maximum number of cake cells that the seminometer can eat.

In the first row of the input, two integers represent r and c (2 ≤ r, c ≤ 10), the number of rows and the number of cake columns. The next R lines have each letter in each - the J-th letter of the line-line shows the contents of the cell in line I and column J, and one of them is:

'.' The character shows a cake cell with no evil strawberry;

The 'S' character shows a cake cell with a bad strawberry.

> 3 4S ... should produce. S

My code returns 12 :

  #include  gt;) {a ++;}} For (j = 0; j & lt; c; j ++) {for (i = 0; i & lt; r; i ++) {cou ++; if (cake [ii] [j] == 'S') {cou = 0; break;}} if (cou> 0) {b ++;}} Cell = cnt + cou - a * b; Printf ("% d", cell); return 0 ;}  

By debugging, I found that (Cake [i] [j] == 's') is wrong, but I do not know the reason.

Correct code change is notified by "change"

  # Include & lt; Stdio.h & gt; Int main (zero) {int r, c; Scan ("% d% d", & amp; r; & amp; c); Four cake [R] [C]; & Lt; --- change i, j, cnt = 0, cou = 0, a = 0, b = 0, cell = 0; // ("J = 0"; J & lt; c; J ++) {changef for "% c" and "cake" for (i = 0; i  0) {a ++; }} For (j = 0; j & lt; c; j ++) {for (i = 0; i  0) {b ++; }} Cell = cnt + cou - a * b; Printf ("% d", cell); Return 0; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -