Ref: UVa Online Judge - UVa 11398 The Base-1 Number System
/*******************************************************/
/* UVa 11398 - The Base-1 Number System */
/* Author: awei0905 [at] awei0905.blogspot.tw */
/* Version: 2017/04/08 */
/*******************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int output = 0, i = 0, flag, len;
char buf[31];
while (scanf("%s", buf)) {
if (buf[0] == '~') break;
if (buf[0] == '#') {
printf("%d\n", output);
output = i = 0;
continue;
}
switch (len = strlen(buf)) {
case 1:
flag = 1;
break;
case 2:
flag = 0;
break;
default:
len -= 2;
if (flag)
for (int j = 0; j < len; j++) {
output <<= 1;
output++;
}
else output <<= len;
}
}
}
Debug: I/O, uDebug0 00 #
0 #
00 000#
0 000#
00 0000#
0 0000#
00 #
00 0 #
0 0000 00 000 0 0000 #
0 0000 000 000 000 0000 #
00 0000 000 0000 0 000 #
~
0
0
199
0
27
127
1
沒有留言:
張貼留言