?? 2192.cpp
字號:
/* This Code is Submitted by wywcgs for Problem 2192 on 2006-04-03 at 19:43:17 */
#include <cstdio>
#include <cctype>
#include <cstring>
const char TYPE[] = "bwdq";
const char TYPE_NAME[][6] = { ".byte", ".word", ".long", ".quad" };
const char HEX[] = "0123456789abcdef";
const int MAX = 128;
char hex(char*&, char*);
int main()
{
char head[4], num[MAX];
int i;
while(scanf("%s", head) != EOF) {
for(i = 0; TYPE[i] != head[1]; i++);
printf("\t%s\t", TYPE_NAME[i]);
while(true) {
char ch;
while((ch = getchar()) == ' ' || ch == '\t');
if(ch == '\n') break;
else if(ch == ',') { printf(", "); continue; }
ungetc(ch, stdin);
scanf("%[0-9a-z]", num);
int len = strlen(num), k = 0;
switch(num[len-1]) {
case 'b': k = 1; break;
case 'h': k = 2; break;
case 'o': k = 3; break;
}
if(!isdigit(num[len-1])) num[--len] = 0;
if(k != 1) {
if(k == 2) printf("0x");
else if(k == 3) putchar('0');
printf("%s", num);
} else {
printf("0x");
char* p = num; int r = len & 3;
if(r != 0) putchar(hex(p, num+r));
while(p != num+len) putchar(hex(p, p+4));
}
}
putchar('\n');
}
return 0;
}
char hex(char*& b, char* e)
{
int v;
for(v = 0; b != e; b++) v = (v << 1) | (*b - '0');
return HEX[v];
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -