2019-07-09啊断更一天,晚上在挣扎一下哈哈哈哈哈哈,这篇比较水(其实是特别水),今天看完了一本小说,一本寒假就该看完的小说,现在才看完,而且一共可能看了不到四小时吧……有点失望,加油凑字数哈哈

晚上看完小说九点多一点,现在再开一片新的是不可能的,不如刷题,于是打开了熟悉的PAT,这次尝试了一下甲级的题,还行,1001很简单,至少题目看得懂,不过以后还是要记一下单词……

就是简单的加法题,开始没看清题目,以为只有一个逗号就行,后面改了两个逗号的情况,所以格式看起来很乱,没有优化好……很丑,凑合看!

#include <iostream>
using namespace std;

int main()
{
    signed int a,b,ans;
    cin>>a>>b;
    ans=a+b;
    
    if(ans>=1000000||ans<=-1000000)
    {
        int h,t,m,s;
        if(ans<0)
        {
            cout<<"-";
            ans=-ans;
        }
        h=ans/1000000;
        cout<<h<<",";
        s=ans%1000000;
        m=s/1000;
        t=s%1000;
        if(m>100)
            cout<<m<<",";
        else if(m==0)
            cout<<"000,";
        else if(m<10)
            cout<<"00"<<m<<",";
        else cout<<"0"<<m<<",";
        if(t==0)
        cout<<"000";
        else if(t<10)
        cout<<"00"<<t;
        else if (t>100)
            cout<<t;
        else cout<<"0"<<t;
    }
    else if(ans>=1000||ans<=-1000)
    {  if(ans<0)
        {
            cout<<"-";
            ans=-ans;
        }
        int head,tail;
        head=ans/1000;
        tail=ans%1000;
        if(tail>100)
            cout<<head<<","<<tail;
        else if(tail==0)
            cout<<head<<","<<"000";
        else if(tail<10)
            cout<<head<<",00"<<tail;
        else cout<<head<<",0"<<tail;
    }
    else 
        cout<<ans;
        return 0;
}

 嘻嘻,十点前!!

发布了42 篇原创文章 · 获赞 16 · 访问量 2890

猜你喜欢

转载自blog.csdn.net/weixin_44412218/article/details/95244539