10×10 のマス目がある。
マス目にそって、矩形が3つある。
ちょうど2つの矩形に含まれているマス目の数を計算せよ。
例えば右図の黒丸(●)が、「ちょうど2つの矩形に含まれているマス目」である。
入力は
5,1-7,9/3,2-8,6/0,5-9,5
こんな感じ。
スラッシュ区切りで3つの矩形が並んでいる。
各矩形は、左上のマスの座標と右下のマスの座標をハイフンでつないだもの。
左上のマスも右下のマスも、矩形の内側になることに注意。
座標はコンマ区切りで x, y の順。
出力は簡単。2つの矩形に含まれているマス目の数を 10進数で出せば良い。
先ほどの入力の場合、
15
と出力すればよい。
| # | 入力 | 期待 | 状況へのリンク |
|---|---|---|---|
| 0 |
5,1-7,9/3,2-8,6/0,5-9,5
|
15
|
リンク |
| 1 |
0,0-9,9/0,0-9,9/0,0-9,9
|
0
|
リンク |
| 2 |
0,0-9,9/0,0-0,9/1,0-9,9
|
100
|
リンク |
| 3 |
2,5-7,6/0,5-7,7/2,0-8,6
|
0
|
リンク |
| 4 |
1,9-4,9/4,9-7,9/0,3-7,4
|
1
|
リンク |
| 5 |
6,1-6,9/5,0-7,4/5,1-7,2
|
6
|
リンク |
| 6 |
4,0-9,8/5,1-6,8/0,2-9,7
|
28
|
リンク |
| 7 |
2,8-8,9/7,9-8,9/8,3-8,9
|
2
|
リンク |
| 8 |
3,3-9,4/0,1-8,4/1,2-8,9
|
12
|
リンク |
| 9 |
2,1-8,3/0,1-3,7/8,3-8,4
|
7
|
リンク |
| 10 |
5,4-6,9/0,0-6,0/5,3-9,8
|
10
|
リンク |
| 11 |
1,1-9,7/1,1-3,8/3,8-7,9
|
22
|
リンク |
| 12 |
2,4-6,7/3,2-7,8/1,0-9,4
|
24
|
リンク |
| 13 |
0,2-1,5/8,1-8,3/1,8-6,8
|
0
|
リンク |
| 14 |
5,2-9,5/9,1-9,2/8,0-8,6
|
5
|
リンク |
| 15 |
5,0-6,4/2,1-6,4/3,8-3,9
|
8
|
リンク |
| 16 |
0,4-6,9/4,1-6,9/7,6-9,7
|
18
|
リンク |
| 17 |
0,0-5,5/0,1-2,8/5,3-9,4
|
17
|
リンク |
| 18 |
0,2-5,6/5,6-8,7/0,1-2,6
|
16
|
リンク |
| 19 |
7,2-8,4/1,0-6,8/1,3-7,6
|
26
|
リンク |
| 20 |
4,3-9,3/0,0-6,5/0,0-4,8
|
31
|
リンク |
| 21 |
3,4-4,6/2,2-4,8/2,0-8,4
|
11
|
リンク |
| 22 |
1,2-6,5/0,5-4,7/2,8-2,9
|
4
|
リンク |
| 23 |
4,1-7,5/2,1-9,9/1,7-2,9
|
23
|
リンク |
| 24 |
1,6-5,6/0,3-5,7/0,2-2,6
|
13
|
リンク |
| 25 |
1,3-3,4/1,4-3,4/9,2-9,9
|
3
|
リンク |
| 26 |
6,3-7,6/2,2-2,3/1,3-9,8
|
9
|
リンク |
| 27 |
2,2-9,7/1,8-9,8/2,2-8,9
|
49
|
リンク |
| 28 |
1,2-6,9/7,6-9,9/4,3-9,9
|
33
|
リンク |
| 29 |
6,0-7,5/0,4-3,8/1,4-5,8
|
15
|
リンク |
| 30 |
2,0-9,7/0,5-3,8/5,1-7,7
|
27
|
リンク |
| 31 |
1,2-8,7/3,1-4,3/2,3-5,8
|
20
|
リンク |
| 32 |
1,0-7,7/0,1-5,4/0,0-2,3
|
19
|
リンク |
| 33 |
2,0-3,7/1,1-3,7/5,3-5,9
|
14
|
リンク |
| 34 |
7,2-9,8/1,0-6,8/0,2-9,9
|
63
|
リンク |
| 35 |
1,1-5,3/0,3-8,7/2,3-8,7
|
32
|
リンク |
| 36 |
3,4-6,6/1,0-9,1/4,0-9,9
|
21
|
リンク |
| 37 |
0,0-4,7/0,5-5,9/0,2-4,5
|
25
|
リンク |
| 38 |
1,1-9,9/2,2-7,4/2,4-7,7
|
30
|
リンク |
| 39 |
3,2-9,9/2,0-6,6/0,5-8,9
|
36
|
リンク |
| 40 |
0,1-8,8/0,5-9,8/2,3-2,4
|
38
|
リンク |
| 41 |
0,0-8,6/4,3-9,9/7,1-9,9
|
29
|
リンク |
| 42 |
0,0-8,8/2,4-9,8/0,1-9,2
|
53
|
リンク |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int solve_impl( char const * src )
{
// NOT_IMPLEMENTED
return 0;
}
// caller should free return value memory.
char const * solve( char const * src )
{
char buffer[ 20 ] = {0};
sprintf( buffer, "%d", solve_impl( src ) );
return strdup(buffer);
}
struct result
{
int success;
int testcount;
};
void test_( struct result * r, char const * src, char const * expected )
{
char const * actual = solve( src );
int okay = 0==strcmp(actual, expected );
if ( okay ){
++r->success;
}
++r->testcount;
printf( "%s : %s->%s(%s)\n", (okay?"ok" : "**NG**"), src, actual, expected );
free( (void*)actual );
}
int main(void)
{
struct result r={0};
#define test(src, expected) test_( &r, src, expected )
/*0*/ test( "5,1-7,9/3,2-8,6/0,5-9,5", "15" );
/*1*/ test( "0,0-9,9/0,0-9,9/0,0-9,9", "0" );
/*2*/ test( "0,0-9,9/0,0-0,9/1,0-9,9", "100" );
/*3*/ test( "2,5-7,6/0,5-7,7/2,0-8,6", "0" );
/*4*/ test( "1,9-4,9/4,9-7,9/0,3-7,4", "1" );
/*5*/ test( "6,1-6,9/5,0-7,4/5,1-7,2", "6" );
/*6*/ test( "4,0-9,8/5,1-6,8/0,2-9,7", "28" );
/*7*/ test( "2,8-8,9/7,9-8,9/8,3-8,9", "2" );
/*8*/ test( "3,3-9,4/0,1-8,4/1,2-8,9", "12" );
/*9*/ test( "2,1-8,3/0,1-3,7/8,3-8,4", "7" );
/*10*/ test( "5,4-6,9/0,0-6,0/5,3-9,8", "10" );
/*11*/ test( "1,1-9,7/1,1-3,8/3,8-7,9", "22" );
/*12*/ test( "2,4-6,7/3,2-7,8/1,0-9,4", "24" );
/*13*/ test( "0,2-1,5/8,1-8,3/1,8-6,8", "0" );
/*14*/ test( "5,2-9,5/9,1-9,2/8,0-8,6", "5" );
/*15*/ test( "5,0-6,4/2,1-6,4/3,8-3,9", "8" );
/*16*/ test( "0,4-6,9/4,1-6,9/7,6-9,7", "18" );
/*17*/ test( "0,0-5,5/0,1-2,8/5,3-9,4", "17" );
/*18*/ test( "0,2-5,6/5,6-8,7/0,1-2,6", "16" );
/*19*/ test( "7,2-8,4/1,0-6,8/1,3-7,6", "26" );
/*20*/ test( "4,3-9,3/0,0-6,5/0,0-4,8", "31" );
/*21*/ test( "3,4-4,6/2,2-4,8/2,0-8,4", "11" );
/*22*/ test( "1,2-6,5/0,5-4,7/2,8-2,9", "4" );
/*23*/ test( "4,1-7,5/2,1-9,9/1,7-2,9", "23" );
/*24*/ test( "1,6-5,6/0,3-5,7/0,2-2,6", "13" );
/*25*/ test( "1,3-3,4/1,4-3,4/9,2-9,9", "3" );
/*26*/ test( "6,3-7,6/2,2-2,3/1,3-9,8", "9" );
/*27*/ test( "2,2-9,7/1,8-9,8/2,2-8,9", "49" );
/*28*/ test( "1,2-6,9/7,6-9,9/4,3-9,9", "33" );
/*29*/ test( "6,0-7,5/0,4-3,8/1,4-5,8", "15" );
/*30*/ test( "2,0-9,7/0,5-3,8/5,1-7,7", "27" );
/*31*/ test( "1,2-8,7/3,1-4,3/2,3-5,8", "20" );
/*32*/ test( "1,0-7,7/0,1-5,4/0,0-2,3", "19" );
/*33*/ test( "2,0-3,7/1,1-3,7/5,3-5,9", "14" );
/*34*/ test( "7,2-9,8/1,0-6,8/0,2-9,9", "63" );
/*35*/ test( "1,1-5,3/0,3-8,7/2,3-8,7", "32" );
/*36*/ test( "3,4-6,6/1,0-9,1/4,0-9,9", "21" );
/*37*/ test( "0,0-4,7/0,5-5,9/0,2-4,5", "25" );
/*38*/ test( "1,1-9,9/2,2-7,4/2,4-7,7", "30" );
/*39*/ test( "3,2-9,9/2,0-6,6/0,5-8,9", "36" );
/*40*/ test( "0,1-8,8/0,5-9,8/2,3-2,4", "38" );
/*41*/ test( "0,0-8,6/4,3-9,9/7,1-9,9", "29" );
/*42*/ test( "0,0-8,8/2,4-9,8/0,1-9,2", "53" );
#undef test
printf( "%d / %d\n", r.success, r.testcount );
return r.testcount==r.success ? 0 : 1;
}