您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

整型相除截断的技巧

2026/4/3 1:26:10发布21次查看
欢迎进入c/c++编程社区论坛,与300万技术人员互动交流 >>进入 该题中主要用到了整型相除截断的技巧。例如,计算行数和输出时候判断是否为最后一列。 [cpp] #include stdio.h #include stdlib.h #include string.h int cmp(const void *_a, const void *_b)
欢迎进入c/c++编程社区论坛,与300万技术人员互动交流 >>进入
    该题中主要用到了整型相除截断的技巧。例如,计算行数和输出时候判断是否为最后一列。
    [cpp]
    #include
    #include
    #include
    int cmp(const void *_a, const void *_b) {
    char *a = (char*)_a;
    char *b = (char*)_b;
    return strcmp(a, b);
    }
    // 根据len长度的字符串,不足以空格补齐
    void print(char st[], int len) {
    int tmp = len - strlen(st);
    printf(%s, st);
    while (tmp--)
    printf( );
    }
    int main() {
    int n;
    char s[105][65];
    while (scanf(%d, &n) != eof) {
    int lmax, c, r;
    lmax = c = r = 0;
    for (int i=0; i    scanf(%s, s[i]);
    int tmp = strlen(s[i]);
    if (tmp > lmax)
    lmax = tmp;
    }
    c = 62 / (lmax+2);                      // 计算列数
    r = (n+c-1) / c;                        // 计算行数
    qsort(s, n, sizeof (s[0]), cmp);
    printf(------------------------------------------------------------\n);
    for (int i=0; i    for (int j=0; j    int tmp = j*r + i;
    if (tmp >= n) continue;
    if (tmp >= ((int)((n-1)/r))*r)  // 如果为最后一列
    print(s[tmp], lmax);
    else
    print(s[tmp], lmax+2);
    }
    printf(\n);
    }
    }
    return 0;
    }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product