1001.A+B Format (20)解题随笔

解题思路:一开始看到题目就觉得应该使用数组方法解题。稍微思考后觉得重点应放在如何每隔三个数字插入一个逗号(相加结果如果是三位数以上的话)。因为A+B的话由题中给出范围可知最多为8位数,故定义一个8个数的数组s[8]。接下来问题就是如何提取和中的每一个位数,最后采取了循环结构:一个数除10取余,赋值给s[i](i=0;i<8;i++)原数除10之后再除10取余,赋值,直至该数小于10(跳出循环),如此循环。最后输出时也是采取循环结构:将数组倒过来输出,(j=i;j>=0;j++),通过选择结构,当(j+1)%3==0 && j!=i时输出一个逗号。

bug调试:一开始是忽略了正负号,最后修改时如果为负数的话,先将其变为正数再去执行数组赋值步骤,到最后输出时,再在前面加上负号即可。

时间: 2024-10-10 00:52:39

1001.A+B Format (20)解题随笔的相关文章

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. 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

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 four digits). Input Each inp

1001. A+B Format (20) (数学啊 ZJU_PAT)

题目链接:http://www.patest.cn/contests/pat-a-practise/1001 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 conta

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 (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

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