问题 E: Jack的A+B
问题 E: Jack的A+B
时间限制: 1 Sec 内存限制: 128 MB
提交: 1996 解决: 601
[提交] [状态] [命题人:jsu_admin]
题目描述
输入
每组输入两个整数a,b
(0<=a,b<=10000000)
输出
样例输入 Copy
- 999 1
- 36 30
- 100000 100
样例输出 Copy
- 1,000
- 66
- 100,100
提示
倒着模拟题意即可,每三位输出一个逗号,注意和为 0 的情况
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- void int2str(int n, char *str) {
- char buf[] = "";
- int i = ;
- int len = ;
- int temp = n < ? -n: n; // temp为n的绝对值
- if (str == NULL)
- {
- return;
- }
- while(temp)
- {
- buf[i++] = (temp % ) + ''; //把temp的每一位上的数存入buf
- temp = temp / ;
- }
- len = n < ? ++i: i; //如果n是负数,则多需要一位来存储负号
- str[i] = ; //末尾是结束符0
- while()
- {
- i--;
- if (buf[len-i-] ==)
- {
- break;
- }
- str[i] = buf[len-i-]; //把buf数组里的字符拷到字符串
- }
- if (i == )
- {
- str[i] = '-'; //如果是负数,添加一个负号
- }
- }
- int main(){
- int a,b;
- int sum;
- char num[];
- while(scanf("%d%d",&a,&b)!=EOF){
- memset(num,,sizeof(num));
- sum = a+b;
- if(sum ==)
- {
- printf("0\n");
- continue;
- }
- int k =;
- int2str(sum,num);
- //printf("%s",num);
- int h = strlen(num)%;
- if(h!=){
- for(int i= ;i<h;i++)
- {
- printf("%c",num[i]);
- }
- if(strlen(num)>)
- printf(",");
- }
- // int k = 0;
- for(int i = h;i<strlen(num);i++)
- {
- printf("%c",num[i]);
- k++;
- if(k%==&&i!=strlen(num)-&&k!=strlen(num)){
- printf(",");
- }
- }
- printf("\n");
- }
- }
- /*
- *@Author: STZG
- *@Language: C++
- */
- #include <bits/stdc++.h>
- #include<iostream>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- #include<cstdio>
- #include<string>
- #include<vector>
- #include<bitset>
- #include<queue>
- #include<deque>
- #include<stack>
- #include<cmath>
- #include<list>
- #include<map>
- #include<set>
- //#define DEBUG
- #define RI register int
- using namespace std;
- typedef long long ll;
- //typedef __int128 lll;
- const int N=;
- const int MOD=1e9+;
- const double PI = acos(-1.0);
- const double EXP = 1E-;
- const int INF = 0x3f3f3f3f;
- int t,n,m,k,q;
- int main()
- {
- #ifdef DEBUG
- freopen("input.in", "r", stdin);
- //freopen("output.out", "w", stdout);
- #endif
- while(scanf("%d%d",&n,&m)!=EOF){
- t=n+m;
- string ans;
- k=;
- while(t){
- k++;
- q=t%;
- ans=(char)(''+q)+ans;
- t/=;
- if(t&&k>=){
- k=;
- ans=','+ans;
- }
- }
- if(n+m<)
- ans='-'+ans;
- if(n+m==)
- ans=''+ans;
- cout<<ans<<endl;
- }
- //cout << "Hello world!" << endl;
- return ;
- }
问题 E: Jack的A+B的更多相关文章
- 解决:编译CM14.1 提示Jack “Out of memory error”错误
Android 7.1编译到33%时出现JDK内存溢出的错误: Out of memory error (version f95d7bdecfceb327f9d201a1348397ed8a84384 ...
- 解决:ERROR: Cannot launch Jack server
问题重现: Install: /home/dinphy/sm/out/target/product/ido/system/lib/libdl.so java -Xmx3500m -jar /home/ ...
- jack报错
[ 29% 17593/59326] Ensure Jack server is installed and startedFAILED: /bin/bash -c "(prebuilts/ ...
- 耳机jack构造及在应用时可能出现的问题
目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为headset,3环耳机称为headphone,两者之间的区别就是4环耳机比3环耳机多个micphone.而J ...
- poj1127 Jack Straws(线段相交+并查集)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Jack Straws Time Limit: 1000MS Memory L ...
- 【屌丝程序的口才逆袭演讲稿50篇】第十篇:程序猿们请看看外面的世界吧【张振华.Jack】
演讲稿主题:<程序猿们请看看外面的世界吧> --作者:张振华Jack 大家都知道我是一个程序猿.几年下来认识了最典型的三个程序猿. ...
- Black Jack
Black Jack 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5602 记忆化搜索 用dp[0][i][j]记录当player为i,banker为 ...
- 1840: Jack Straws
1840: Jack Straws 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 168 测试通过:129 描述 I ...
- com.android.jack.CommandLine: Internal compiler error
Android studio编译的时候出现错误: SEVERE: com.android.jack.CommandLine: Internal compiler error Error:Executi ...
- HP Jack介绍
转载:https://www.cnblogs.com/Peter-Chen/p/3999212.html 目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为he ...
随机推荐
- Delphi-----接口请求,Get与Post
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- python-类对象的遍历操作
视频教程 https://study.163.com/course/courseLearn.htm?courseId=1005985001#/learn/video?lessonId=10533511 ...
- c++ string转char*
1.如果要将string转换为char*,可以使用string提供的函数c_str() ,或是函数data(),data除了返回字符串内容外,不附加结束符'\0',而c_str()返回一个以‘\0’结 ...
- IDEA提交代码到github
GIT客户端安装及idea配置github账号并提交代码到GIT参考资料:https://blog.csdn.net/qq_31405633/article/details/88193119 1. 选 ...
- ubantu apt-get install安装php及开展
.安装php apt-get install libapache2-mod-php5 php5 报错 E: Package 'libapache2-mod-php5' has no installat ...
- linux 多进程并发服务__关于子进程回收的方法
以TCPServ 服务程序来说: 1)父进程:负责系统初始化,以及监听(listen),接受连接请求(accept);其中accept 默认阻塞调用. 2)每接受一个连接请求,动态新建(fork)一个 ...
- Linux超全实用指令大全
参考 Linux超全实用指令大全
- Android传感器系统架构【转】
本文转载自:http://blog.csdn.net/qianjin0703/article/details/5942579 版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 体系结构 2. ...
- Linux内核调试方法总结之调试宏
本文介绍的内核调试宏属于静态调试方法,通过调试宏主动触发oops从而打印出函数调用栈信息. 1) BUG_ON 查看bug处堆栈内容,主动制造oops Linux中BUG_ON,WARN_ON用于调试 ...
- 三十三、python中configparser配置文件相关操作
配置文件ini [a1]age = 18sex = 'man' [a2]age = 19sex = 'woman'name = False 1.对配置文件进行操作 import configparse ...