PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏
1001. A+B Format (20)
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
- 很水的题,ab都比较小,直接算出答案,按位放到数组,注意3位移,
#include<stdio.h> int main() { int a,b,c,i,s[1000],j,k,x,n,y; while(scanf("%d%d",&a,&b)!=EOF) { c=a+b; k=c; i=0; if(c==0) printf("0\n"); else { while(c!=0) { s[i]=c%10; c=c/10; i++; j=i; } if(k<0) { printf("-"); for(i=0;i<j;i++) s[i]=-s[i]; } x=j%3; y=x; for(i=j-1;i>j-x-1;i--) printf("%d",s[i]); n=0; for(i=j-x-1;i>=0;i--) { if(n++%3==0&&y++!=0) printf(","); printf("%d",s[i]); } printf("\n"); } } return 0;}
PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏的更多相关文章
- PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏
1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT甲 1007. Maximum Subsequence Sum (25) 2016-09-09 22:56 41人阅读 评论(0) 收藏
1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- PAT甲 1006. Sign In and Sign Out (25) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- Codeforces812B Sagheer, the Hausmeister 2017-06-02 20:47 85人阅读 评论(0) 收藏
B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input s ...
- PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT甲 1046. Shortest Distance (20) 2016-09-09 23:17 22人阅读 评论(0) 收藏
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT甲 1041. Be Unique (20) 2016-09-09 23:14 33人阅读 评论(0) 收藏
1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being uniqu ...
- PAT甲 1011. World Cup Betting (20) 2016-09-09 23:06 18人阅读 评论(0) 收藏
1011. World Cup Betting (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Wit ...
- PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
随机推荐
- ubuntu 安装 selenium selenium操作 chrome
重装虚拟机,好多包需要重装,sele这个记得当时就找了好久的完整重装方法,这次又找了好久,,,省的下次再这样,记录下来..... ubuntu16.04 4安装seleniumsudo pip ins ...
- Openning SharePoint - 80 website gives HTTP 404 Error, The webpage cannot be found ! on SharePoint 2013
ask: I tried to open the SharePoint - 80 throw Browse in IIS, but I get HTTP 404 Error (The webpage ...
- Eletron 打开文件夹,截图
1.shell.openItem(fullPath) var fullpath = path.join(processPath)+Math.random()+".png"; she ...
- $.ajax dataType设置为json 回调函数不执行
请求方式如下: $.xpost = function (url, data) { return $.ajax({ url: url, type: "POST", dataType: ...
- EnumMap实现类
从名字上看出来,EnumMap是为枚举类服务的,它的key不能为null,在创建它的时候,必须要指定一个枚举类,如: EnumMap enumMap = new EnumMap(Season.clas ...
- Layouts
[Layouts] Each layout file must contain exactly one root element, which must be a View or ViewGroup ...
- luoguP1196(带权并查集)
题目链接:https://www.luogu.org/problemnew/show/P1196 思路: 带权并查集.对每个结点,构造表示该结点的头结点,该结点距头结点的距离,该列的大小3个数组. 在 ...
- 10.Regular Expression Matching (String; Back-Track,DP)
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- Mac 终端便利工具: 管理工具-Homebrew 和提示工具oh my zsh
命令行提示工具 第一步: Homebrew - 安装与使用 https://blog.csdn.net/sir_coding/article/details/77509602 Homebrew安装问题 ...
- php 函数中静态变量的问题
<?php function msg() { static $a = 0; echo $a++, '<br />'; } msg(); msg(); msg(); 上述代码,分别输出 ...