PAT 1001. A+B Format

#include<stdio.h>
int a, b;
int sum;
int main(){
	while (scanf("%d %d", &a, &b)!=EOF){
		sum = a + b;
		if (sum < 1000&&sum>-1000)printf("%d\n", sum);
		else{
			int sum1 = sum % 1000;
			int sum2 = sum / 1000;
			int sum3 = 0;
			if (sum2 != 0){
				sum3 = sum2 / 1000;
			}
			sum2 = sum2 % 1000;
			if (sum3 != 0){
				printf("%d,%03d,%03d\n", sum3 % 1000, sum2 < 0 ? -sum2 : sum2, sum1 < 0 ? -sum1 : sum1);
			}
			else
			printf("%d,%03d\n", sum2, sum1<0?-sum1:sum1);

		}

	}
}

  

时间: 2024-10-06 00:40:53

PAT 1001. A+B Format的相关文章

PAT 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 contains a pair of integer

PAT 1001. A+B Format(水题)

#include<cstdio> #include<cstring> using namespace std; char s[10]; int main() { int a,b; while(scanf("%d%d",&a,&b)==2) { memset(s,0,sizeof(s)); a=a+b; if(a==0) { printf("0\n"); continue; } int aa=a; b=0; if(a<0)

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

PAT 甲级 1001 A+B Format (20)(20 分)

1001 A+B Format (20)(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

PAT 1001

1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 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 four d

PAT A1001 A+B Format

PAT A1001 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 ca

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的PAT甲级证书考试,对网站上的题目进行总结分析: 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). 计算a+b的值并以一定格式输出其和sum(数字需要

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