我是靠谱客的博主 酷酷夏天,这篇文章主要介绍1001 A+B Format,现在分享给大家,希望可以做个参考。

采用to_string

用i%3==s.length()%3控制逗号输出

#include<bits/stdc++.h>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	string ans=to_string(abs(a+b));
	if(a+b<0)cout<<"-";
	for(int i=0;i<ans.length();i++){
		cout<<ans[i];
		if((i+1)%3==ans.length()%3&&i+1!=ans.length())cout<<",";
	}
}

最后

以上就是酷酷夏天最近收集整理的关于1001 A+B Format的全部内容,更多相关1001内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(124)

评论列表共有 0 条评论

立即
投稿
返回
顶部