PAT (Advanced Level) 1001. A+B Format (20)

简单题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

int a,b,tot,cnt;
int u[20];
char ans[100];

int main()
{
    while(~scanf("%d%d",&a,&b))
    {
        a=a+b;
        if(a==0)
        {
            printf("0\n");
            continue;
        }
        int tmp=abs(a);
        tot=0,cnt=0;
        while(tmp) u[tot++]=tmp%10,tmp=tmp/10;

        for(int i=0; i<tot; i++)
        {
            ans[cnt++]=u[i]+‘0‘;
            if((i+1)%3==0&&tot-i!=1) ans[cnt++]=‘,‘;
        }
        if(a<0) ans[cnt++]=‘-‘;
        for(int i=cnt-1; i>=0; i--) printf("%c",ans[i]);
        printf("\n");
    }
    return 0;
}
时间: 2024-08-26 23:24:17

PAT (Advanced Level) 1001. A+B Format (20)的相关文章

PAT Advanced level 1001 A+B Format

Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Specification: Each input file contains one test case. Each case contains a pa

PTA (Advanced Level)1001.A+B Format

Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Specification: Each input file contains one test case. Each case contains a pa

PAT (Advanced Level) 1005. Spell It Right (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<vector> using namespace std; const int maxn=100+10; char s[maxn]; int tmp[maxn],tot; char ans[15][7]={ "zero&q

PAT (Advanced Level) 1019. General Palindromic Number (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; int s[10000],tot; int n,b; bool check() { for(int i=0; i<=tot

PAT (Advanced Level) 1027. Colors in Mars (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; void pri(int a) { if (a <= 9) printf("%d", a); else printf("%c", a-10+'A'); } void print(int a){ if (a >= 13

PAT (Advanced Level) 1054. The Dominant Color (20)

简单题 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; int a[500000]; int n,m; int main() { scanf("%d%d",&n,&m); for(int i=0;i&

PAT (Advanced Level) 1011. World Cup Betting (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; double a[5][5],Max[5]; double ans=1; int main() { for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) scanf(&qu

1001. A+B Format (20) ——PAT (Advanced Level) Practise

题目信息: 1001. A+B Format (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than

【PAT】1001. A+B Format (20)

1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Each input file contains one test case. Each case cont