探索生活百科

PAT Level A 1001 简单 A+B 特殊输出格式

探索生活百科
题链接:https://www.scooter-sidecars.com/problem-sets/994805342720868352/problems/994805528788582400 我今年秋天或冬天想参加 PAT Level A 考试,我开始研究问题。 20分的题还是蛮不错的,加油吧!奥利给! (其实我懒得写博客,所以就贴出代码来记录一下。 #包括 #包括 typedef 长长 ll; a[100],b[100]; int main() {ll x,y;scanf("%lld %lld",&x,&y);ll sum=x+y;ll ct=0;bool flag=0;if(sum<0)flag=1,sum=-sum;while(sum){a[++ct]=sum%10;sum/=10;}for(ll i=ct;i>=1;i--) {b[ct-i+1]=a[i];}if(ct<=3)printf("%lld\n",x+y);else{if(flag)printf("-"); ll tmp=ct%3;for(ll i=1;i<=tmp;i++){printf("%lld",b[i]);}if(tmp)printf(",");for(ll i=tmp+1;i<=ct;i++){printf("%lld",b[i]);if((i-tmp)%3==0&&i!=ct)printf(","); }printf("\n");}scanf("%lld",&x); }

发表评论 (已有0条评论)

还木有评论哦,快来抢沙发吧~