/ 科创班 /

记录详情

Accepted

/in/foo.c: In function 'main':
/in/foo.c:21:19: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
         int len = strlen(p);
                   ^~~~~~
/in/foo.c:21:19: warning: incompatible implicit declaration of built-in function 'strlen'
/in/foo.c:21:19: note: include '<string.h>' or provide a declaration of 'strlen'
# 状态 耗时 内存占用
#1 Accepted 10ms 472.0 KiB

代码

#include <stdio.h>

int x2i(char c)
{
    if (c >= 'A') 
        return c - 55;
    else 
        return c - 48;
}

int main()
{
    int i, j, n;
    char a[10][100001];
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%s", a[i]);
    for (i = 0; i < n; i++)
    {
        char* p = a[i];
        int len = strlen(p);
        if (len % 3 == 1)
        {
            printf("%o", x2i(p[0]));
            j = 1;
        }
        else if (len % 3 == 2)
        {
            printf("%o", x2i(p[0])*16+x2i(p[1]));
            j = 2;
        }
        else
        {
            printf("%o", x2i(p[0])*256+x2i(p[1])*16+x2i(p[2]));
            j = 3;
        }
        for (; j < len; j += 3)
            printf("%04o", x2i(p[j])*256+x2i(p[j+1])*16+x2i(p[j+2]));
        printf("\n");
    }
    return 0;
}

信息

递交者
类型
递交
题目
十六进制转八进制
题目数据
下载
语言
C
递交时间
2018-10-17 20:49:09
评测时间
2018-10-17 20:49:09
评测机
分数
100
总耗时
10ms
峰值内存
472.0 KiB