SRM 571 DIV2 250

(問題文は省略)

強いてポイントを挙げるなら、

"o"は左詰めで置かれるので、starを前方からカウントする場合、"-"の出現時点で、そのステージのループは打ちきってよい。

ぐらいでしょうか。

      1 #include <stdio.h>
      2 
      3 #define NUMOF(array)    (sizeof(array)/sizeof(*array))
      4 
      5 int FoxAndGame_countStars(const char** result, const int numof_stages)
      6 {
      7     int stage_i;
      8     int star_i;
      9     int numof_stars = 0;
     10 
     11     /* loop for stages */
     12     for(stage_i=0; stage_i<numof_stages; stage_i++){
     13         /* loop for stars */
     14         for(star_i=0; star_i<3; star_i++){
     15             if(result[stage_i][star_i]=='-'){
     16                 break;          
     17             }           
     18             numof_stars++;
     19         }       
     20     }   
     21 
     22     return numof_stars;
     23 }
     24 
     25 int main(void)
     26 {
     27     const char *result[] = \ 
     28         {"---", \
     29          "o--", \
     30          "oo-", \
     31          "ooo", \
     32          "ooo", \
     33          "oo-", \
     34          "o--", \
     35          "---"}; 
     36 
     37     printf("Returns: %d\n", FoxAndGame_countStars(result, NUMOF(result)));
     38 
     39     return 0;
     40 }