Submission #32365


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdio>
#include <algorithm>
using std::min;
constexpr unsigned MASK = 0xFFu;
inline int getR(const unsigned c){ return ( (c>>16) & MASK ); }
inline int getG(const unsigned c){ return ( (c>>8 ) & MASK ); }
inline int getB(const unsigned c){ return (c & MASK); }
inline unsigned makeRGB(int r, int g, int b)
{
return ( (r<<16) | (g<<8) | (b) );
}
unsigned update(unsigned color, int R, int G, int B)
{
// -1 なら現在の color の値を, そうでなければ引数の値にする
int newR = (R == -1) ? getR(color) : R;
int newG = (G == -1) ? getG(color) : G;
int newB = (B == -1) ? getB(color) : B;
return makeRGB(newR, newG, newB);
}
unsigned reverse(unsigned c)
{
return makeRGB(255 - getR(c),
255 - getG(c),
255 - getB(c));
}
int main()
{
unsigned color; //C言語では, 論理シフトの時は符号なし整数を使う
char com[32];
scanf("%X", &color);
// 今回の場合は,先頭の文字だけ見ればOK
for(;;)
{
int r, g, b;
scanf("%s", com);
if (*com == 'q') { //quit
break;
}
switch(com[0])
{
case 'u': //update
scanf("%d%d%d", &r, &g, &b);
color = update(color, r, g, b);
break;
case 'r': //reverse
color = reverse(color);
break;
case 's': //右shift
scanf("%d", &r);
if (r < 0) {
color <<= -r;
color &= 0xFfFfFf;
}
else {
color >>= r;
}
break;
case 'd': //disp
printf("%06X\n", color);
break;
}
}
return (0);
}

ステータス

項目 データ
問題 0900 - あーるじーびー操作
ユーザー名 Arumakan_ei1727
投稿日時 2018-03-22 23:46:18
言語 C++17
状態 Accepted
得点 3
ソースコード長 1768 Byte
最大実行時間 39 ms
最大メモリ使用量 3556 KB

セット

セット 得点 Cases
1 ALL 3 / 3 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input01 AC 28 ms 608 KB
1
input02 AC 24 ms 848 KB
1
input03 AC 28 ms 1092 KB
1
input04 AC 23 ms 1072 KB
1
input05 AC 32 ms 1188 KB
1
input06 AC 21 ms 1424 KB
1
input07 AC 24 ms 1540 KB
1
input08 AC 25 ms 1780 KB
1
input09 AC 33 ms 2144 KB
1
input10 AC 32 ms 2508 KB
1
input11 AC 32 ms 2872 KB
1
input12 AC 16 ms 2848 KB
1
input13 AC 22 ms 2960 KB
1
input14 AC 22 ms 3076 KB
1
input15 AC 39 ms 3320 KB
1
input16 AC 31 ms 3556 KB
1
input_sample1 AC 20 ms 3540 KB
1
input_sample2 AC 21 ms 3520 KB
1
input_sample3 AC 18 ms 3504 KB
1
input_sample4 AC 14 ms 3492 KB
1