使用了C语言,小数据文件提交通过。 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> #define BUFSIZE 256 char D2B(int K) { unsigned char temp = 0x00;; char quotient = K; char mod = 0; int i = 0; //printf("Kinit:%d/n",K); while (quotient != 0) { mod = quotient % 2; if (mod == 1) { temp = temp >> 1; temp = temp | 0x80; //printf("Ked1:%02x/n",temp); } else { temp = temp >> 1; temp = temp & 0x7f; //printf("Ked0:%02x/n",temp); } quotient = quotient / 2; //printf("King:%d/n",quotient); i++; } while (i != 8) { temp = temp >> 1; i++; } //printf("K:%02x/n",temp); return temp; } int GetLen(char K) { int temp = 0; int i; for (i = 0; i < 8; i++) { if (K & 1<<i) { temp ++; } else { break; } } //printf("len:%d/n",temp); return temp; } int main(int argc , char *argv[]) { FILE *fd; char buf[256]={'/0'}; int T, N, K; int i; if (argc != 2) { fprintf(stderr,"Usage: ./a.out A-small-practice.in/n"); return 0; } fd = fopen(argv[1], "r"); if (fd == NULL) { perror("Open file failed./n"); return 0; } fgets(buf, BUFSIZE, fd); sscanf(buf,"%d/n",&T); memset(buf, '/0', BUFSIZE); //printf("T:%d/n",T); #if 1 i = 1; while( i<=T ) { fgets(buf, BUFSIZE, fd); sscanf(buf, "%d %d/n", &N, &K); //printf("%d %d/n",N, K); //D2B(K); if ( GetLen(D2B(K)) >= N ) { //printf("%d %d/n",N, K); printf("Case #%d: ON/n",i); } else { printf("Case #%d: OFF/n",i); } memset(buf, '/0', BUFSIZE); i++; } #endif fclose(fd); }