发布者认证信息(营业执照和身份证)未完善,请登录后完善信息登录
终于认识考研英语每日一练
教育培训

终于认识考研英语每日一练

产品单价:面议

最小起订:暂未填写

供货总量:暂未填写

发货期限:请联系商家

有效期至:长期有效

勤学思教育网
未认证 谨防假冒!

产品详情

  考研英语就要来临,小编盘点了以下知识点及练习题分享,希望对大家有所帮助,预祝大家高分通过!
  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 pair of integers a and b where 10^6 ≤ a, b ≤ 10 ^6 . The numbers are separated by a sPACe.
  Output Specification: For each test case, you should output the sum ofa and b in one line. The sum must be written in the standard format. Sample Input: -1000000^9 Sample Output: -999,991
  思路:这道题属于基础题,难度不高,但可以考虑怎么用更加高效的方法实现,目前想到的是很基础的方法,即将两数相加以后,将结果的每一位分步存进一个数组中,在按原本的顺序打印出来,并在合适的位置加上逗号以及正负号。
  这道题目首先一个问题就是,判断的过程肯定得是从低位开始,这是因为我们不知道这个数究竟有几位,当然也可以用一个循环先判断结果的位数,我这里采用的是从低位到高位进行判断,从低到高将数存进数组,需要注意的是,数组里的数的顺序和将要输出的顺序是相反的,因此需要从后往前打印,代码如下:
  include int abs(int i){ if(i1000000 || a1000000) return -1;*/ c = a b; for(i=0; i=0;i--){ if(temp[i] == 10) printf(","); else printf("%d", abs(temp[i])); } return 0; }至于逗号,我是用的是在需要加逗号的地方,给的数组赋值为10,输出的时候,遇到10就打印逗号就行。整个程序时间复杂度为0(n)。
  

发布时间:2021-12-04 18:20  点击:96

所在地:湖北

相关分类