PTA甲级

PTA[Advanced] 1001 A+B

2018-12-31  本文已影响0人  zilla

题目链接

灰灰公众号的题解

我的题解

#include <stdio.h>
#include <cstdlib>

int main(){
    int a,b,res;
    while (scanf("%d%d",&a,&b)!=EOF){
        res=a+b;
        int abst=abs(res);
        if(res<0)
            printf("-");
        if(abst/1000000!=0) {
            printf("%d,", abst / 1000000);
            abst%=1000000;
            printf("%03d,", abst / 1000);
            printf("%03d\n", abst % 1000);
        } else if(abst/1000!=0){
            printf("%d,", abst / 1000);
            printf("%03d\n", abst % 1000);
        } else{
            printf("%d\n",abst%1000);-
        }
    }
    return 0;
}

研究了一下python版题解

#python
//灰灰考研@一航
a,b = map(int,input().split())
print(format(a+b,','))

简洁的惊人啊。
format()格式化数字
str.format()

map函数
用于处理一个列表里的元素,接受函数和列表作为参数,然后返回函数处理之后的新列表

递归式学习的懵逼小熊猫新的一年要加油啦
上一篇 下一篇

猜你喜欢

热点阅读