PAT甲级1001水题飘过

 1 #include<iostream>
 2 using namespace std;
 3
 4 int main(){
 5     int a, b;
 6     while(scanf("%d%d", &a, &b) != EOF){
 7         int c = a + b;
 8         if(c == 0) printf("0\n");
 9         else{
10             if(c < 0){
11                 printf("-");
12                 c = -c;
13             }
14             int k[5];
15             int cnt = 0;
16             while(c != 0){
17                 int x = c % 1000;
18                 c /= 1000;
19                 k[cnt++] = x;
20             }
21             for(int i = cnt-1; i >= 0; i--){
22                 if(i != cnt-1){
23                     printf("%03d", k[i]);
24                 }else{
25                     printf("%d", k[i]);
26                 }
27                 if(i != 0) printf(",");
28             }
29             printf("\n");
30         }
31     }
32     return 0;
33 }

原文地址:https://www.cnblogs.com/findview/p/11632003.html

时间: 2024-10-08 13:47:07

PAT甲级1001水题飘过的相关文章

PAT甲级1002水题飘过

1 #include<iostream> 2 #include<string.h> 3 using namespace std; 4 5 double a[1005]; 6 7 int main(){ 8 int n1, n2; 9 while(scanf("%d", &n1) != EOF){ 10 memset(a, 0, sizeof(a)); 11 for(int i = 1; i <= n1; i++){ 12 int x; 13 dou

pat甲级 1001 A+B Format

要写甲级题,首要任务是解决英文这个大难题. 困难词汇(我不认识的):calculate计算  standard format 标准格式  digits数字  separated 分离  commas逗号 这道题的大致意思是,给出两个数a和b,并且a和b都大于等于-10的6次方小于等于10的6次方,求出a和b的和,将这个和,每三个数字用逗号分隔一下.看懂了题意以后这题就简单了 ac代码如下: #include <iostream> #include<string> #include&

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 point(s)) 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

PAT甲级 1001

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 Specification: Each input file contains one test case.

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 i

PAT 甲级 1001 A+B Format

https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 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). Inpu

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) Sample Input: -1000000 9 Sample Output: -999,991 第一种方法,注意题目说明的数字范围,及时处理越界即可. 为啥捏,因为 in

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(数字需要