算法学习之路|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).

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 integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input
-1000000 9
Sample Output
-999,991
解题思路:
给出两个整数a,b,求和并按照指定格式输出,简单的模拟一下就行。

#include<cstdio>
void myprint(int num){
  if(num<0){
    printf("-");
    num=-num;
  }
  if(num>999999){
    printf("%d,%d%d%d,%d%d%d",num/1000000,num/100000%10,num/10000%10,num/1000%10,num/100%10,num/10%10,num%10);
  }
  else if(num>999){
    printf("%d,%d%d%d",num/1000,num/100%10,num/10%10,num%10);
  }
  else{
    printf("%d",num);
  }
} 
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  int sum=a+b;
  myprint(sum);
  return 0; 
}
目录
相关文章
|
2月前
|
机器学习/深度学习 数据采集 搜索推荐
Paper Digest | 突破个性化推荐数据稀疏性:长尾增强的图对比学习算法研究
本文提出了一种新的长尾增强的图对比学习方法(LAGCL),该方法促使模型同时兼顾头部节点与尾部节点之间的知识,并通过长尾增强技术来使模型产出更均匀更准确的节点表征,从而改进基于 GNN 的推荐任务。
|
2月前
|
算法 网络协议 Linux
【Cisco Packet Tracer】交换机的自学习算法
【Cisco Packet Tracer】交换机的自学习算法
54 0
|
3月前
|
算法 安全 数据安全/隐私保护
C/C++学习 -- RSA算法
C/C++学习 -- RSA算法
34 0
|
3月前
|
机器学习/深度学习 算法
机器学习 - [集成学习]Bagging算法的编程实现
机器学习 - [集成学习]Bagging算法的编程实现
32 1
|
9天前
|
机器学习/深度学习 算法 前端开发
Scikit-learn进阶:探索集成学习算法
【4月更文挑战第17天】本文介绍了Scikit-learn中的集成学习算法,包括Bagging(如RandomForest)、Boosting(AdaBoost、GradientBoosting)和Stacking。通过结合多个学习器,集成学习能提高模型性能,减少偏差和方差。文中展示了如何使用Scikit-learn实现这些算法,并提供示例代码,帮助读者理解和应用集成学习提升模型预测准确性。
|
9天前
|
机器学习/深度学习 算法 Python
使用Python实现集成学习算法:Bagging与Boosting
使用Python实现集成学习算法:Bagging与Boosting
19 0
|
16天前
|
算法
【算法学习--字符串】(不含KMP算法)
【算法学习--字符串】(不含KMP算法)
|
1月前
|
Rust Dart 算法
55.3k star!开源算法教程,附带动画图解,学习算法不再苦恼!
55.3k star!开源算法教程,附带动画图解,学习算法不再苦恼!
|
1月前
|
算法 C++ 计算机视觉
Opencv(C++)学习系列---Laplacian拉普拉斯边缘检测算法
Opencv(C++)学习系列---Laplacian拉普拉斯边缘检测算法
|
1月前
|
算法 C++ 计算机视觉
Opencv(C++)学习系列---Canny边缘检测算法
Opencv(C++)学习系列---Canny边缘检测算法