问题 E: Jack的A+B

时间限制: 1 Sec  内存限制: 128 MB
提交: 1996  解决: 601
[提交] [状态] [命题人:jsu_admin]

题目描述

现在有整数a,b,请按西方数字数量级方式输出a+b

输入

题目有多组测试数据
每组输入两个整数a,b
(0<=a,b<=10000000)

输出

输出西方数字数量级的a+b

样例输入 Copy

  1. 999 1
  2. 36 30
  3. 100000 100

样例输出 Copy

  1. 1,000
  2. 66
  3. 100,100

提示

输出的数从最低位起,每三位用逗号隔开
 

倒着模拟题意即可,每三位输出一个逗号,注意和为   0 的情况

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. void int2str(int n, char *str) {
  5. char buf[] = "";
  6. int i = ;
  7. int len = ;
  8. int temp = n < ? -n: n; // temp为n的绝对值
  9.  
  10. if (str == NULL)
  11. {
  12. return;
  13. }
  14. while(temp)
  15. {
  16. buf[i++] = (temp % ) + ''; //把temp的每一位上的数存入buf
  17. temp = temp / ;
  18. }
  19.  
  20. len = n < ? ++i: i; //如果n是负数,则多需要一位来存储负号
  21. str[i] = ; //末尾是结束符0
  22. while()
  23. {
  24. i--;
  25. if (buf[len-i-] ==)
  26. {
  27. break;
  28. }
  29. str[i] = buf[len-i-]; //把buf数组里的字符拷到字符串
  30. }
  31. if (i == )
  32. {
  33. str[i] = '-'; //如果是负数,添加一个负号
  34. }
  35. }
  36.  
  37. int main(){
  38. int a,b;
  39. int sum;
  40. char num[];
  41. while(scanf("%d%d",&a,&b)!=EOF){
  42. memset(num,,sizeof(num));
  43. sum = a+b;
  44. if(sum ==)
  45. {
  46. printf("0\n");
  47. continue;
  48. }
  49. int k =;
  50. int2str(sum,num);
  51. //printf("%s",num);
  52. int h = strlen(num)%;
  53. if(h!=){
  54.  
  55. for(int i= ;i<h;i++)
  56. {
  57. printf("%c",num[i]);
  58. }
  59. if(strlen(num)>)
  60. printf(",");
  61. }
  62. // int k = 0;
  63. for(int i = h;i<strlen(num);i++)
  64. {
  65.  
  66. printf("%c",num[i]);
  67. k++;
  68. if(k%==&&i!=strlen(num)-&&k!=strlen(num)){
  69. printf(",");
  70. }
  71. }
  72. printf("\n");
  73. }
  74. }
  1. /*
  2. *@Author: STZG
  3. *@Language: C++
  4. */
  5. #include <bits/stdc++.h>
  6. #include<iostream>
  7. #include<algorithm>
  8. #include<cstdlib>
  9. #include<cstring>
  10. #include<cstdio>
  11. #include<string>
  12. #include<vector>
  13. #include<bitset>
  14. #include<queue>
  15. #include<deque>
  16. #include<stack>
  17. #include<cmath>
  18. #include<list>
  19. #include<map>
  20. #include<set>
  21. //#define DEBUG
  22. #define RI register int
  23. using namespace std;
  24. typedef long long ll;
  25. //typedef __int128 lll;
  26. const int N=;
  27. const int MOD=1e9+;
  28. const double PI = acos(-1.0);
  29. const double EXP = 1E-;
  30. const int INF = 0x3f3f3f3f;
  31. int t,n,m,k,q;
  32.  
  33. int main()
  34. {
  35. #ifdef DEBUG
  36. freopen("input.in", "r", stdin);
  37. //freopen("output.out", "w", stdout);
  38. #endif
  39. while(scanf("%d%d",&n,&m)!=EOF){
  40. t=n+m;
  41. string ans;
  42. k=;
  43. while(t){
  44. k++;
  45. q=t%;
  46. ans=(char)(''+q)+ans;
  47. t/=;
  48. if(t&&k>=){
  49. k=;
  50. ans=','+ans;
  51. }
  52. }
  53. if(n+m<)
  54. ans='-'+ans;
  55. if(n+m==)
  56. ans=''+ans;
  57. cout<<ans<<endl;
  58. }
  59.  
  60. //cout << "Hello world!" << endl;
  61. return ;
  62. }

问题 E: Jack的A+B的更多相关文章

  1. 解决:编译CM14.1 提示Jack “Out of memory error”错误

    Android 7.1编译到33%时出现JDK内存溢出的错误: Out of memory error (version f95d7bdecfceb327f9d201a1348397ed8a84384 ...

  2. 解决:ERROR: Cannot launch Jack server

    问题重现: Install: /home/dinphy/sm/out/target/product/ido/system/lib/libdl.so java -Xmx3500m -jar /home/ ...

  3. jack报错

    [ 29% 17593/59326] Ensure Jack server is installed and startedFAILED: /bin/bash -c "(prebuilts/ ...

  4. 耳机jack构造及在应用时可能出现的问题

    目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为headset,3环耳机称为headphone,两者之间的区别就是4环耳机比3环耳机多个micphone.而J ...

  5. poj1127 Jack Straws(线段相交+并查集)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Jack Straws Time Limit: 1000MS   Memory L ...

  6. 【屌丝程序的口才逆袭演讲稿50篇】第十篇:程序猿们请看看外面的世界吧【张振华.Jack】

    演讲稿主题:<程序猿们请看看外面的世界吧>                      --作者:张振华Jack     大家都知道我是一个程序猿.几年下来认识了最典型的三个程序猿.     ...

  7. Black Jack

    Black Jack 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5602 记忆化搜索 用dp[0][i][j]记录当player为i,banker为 ...

  8. 1840: Jack Straws

    1840: Jack Straws 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 168            测试通过:129 描述 I ...

  9. com.android.jack.CommandLine: Internal compiler error

    Android studio编译的时候出现错误: SEVERE: com.android.jack.CommandLine: Internal compiler error Error:Executi ...

  10. HP Jack介绍

    转载:https://www.cnblogs.com/Peter-Chen/p/3999212.html 目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为he ...

随机推荐

  1. Delphi-----接口请求,Get与Post

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  2. python-类对象的遍历操作

    视频教程 https://study.163.com/course/courseLearn.htm?courseId=1005985001#/learn/video?lessonId=10533511 ...

  3. c++ string转char*

    1.如果要将string转换为char*,可以使用string提供的函数c_str() ,或是函数data(),data除了返回字符串内容外,不附加结束符'\0',而c_str()返回一个以‘\0’结 ...

  4. IDEA提交代码到github

    GIT客户端安装及idea配置github账号并提交代码到GIT参考资料:https://blog.csdn.net/qq_31405633/article/details/88193119 1. 选 ...

  5. ubantu apt-get install安装php及开展

    .安装php apt-get install libapache2-mod-php5 php5 报错 E: Package 'libapache2-mod-php5' has no installat ...

  6. linux 多进程并发服务__关于子进程回收的方法

    以TCPServ 服务程序来说: 1)父进程:负责系统初始化,以及监听(listen),接受连接请求(accept);其中accept 默认阻塞调用. 2)每接受一个连接请求,动态新建(fork)一个 ...

  7. Linux超全实用指令大全

    参考 Linux超全实用指令大全

  8. Android传感器系统架构【转】

    本文转载自:http://blog.csdn.net/qianjin0703/article/details/5942579 版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 体系结构 2. ...

  9. Linux内核调试方法总结之调试宏

    本文介绍的内核调试宏属于静态调试方法,通过调试宏主动触发oops从而打印出函数调用栈信息. 1) BUG_ON 查看bug处堆栈内容,主动制造oops Linux中BUG_ON,WARN_ON用于调试 ...

  10. 三十三、python中configparser配置文件相关操作

    配置文件ini [a1]age = 18sex = 'man' [a2]age = 19sex = 'woman'name = False 1.对配置文件进行操作 import configparse ...