Judge Info

  • Memory Limit: 32768KB
  • Case Time Limit: 10000MS
  • Time Limit: 10000MS
  • Judger: Normal

Description

Please calculate the answer of A+B and the answer of A-B, both A and B are integer.

Input

The first line of input contains , the number of test cases. There is only line for each test case. It contains two integers .

Output

For each test case, output two lines A+B and A-B.

Sample Input

3
1 2
1 1
-1 -1

Sample Output

3
-1
2
0
-2
0

题解:

1.  调试了很多遍,WA,之后朋友用python 测试很多大数据,我都测试了,数据正常,但还是WA,问了cxc,才发现,擦擦,尼玛,爆粗有木有? 调代码调了四个多小时只是没考虑前导0 ?带前导0也算神马整数  ,  -000001   是  -1   0000002  是 2  , 哪有这么无语的数据,擦擦!!

2.  第二次调试发现前导0去掉了。但是忽略了一个重要的数据,妹的 -00000   减去    +0000000   等于  -0 的有木有?   又单独考虑0的符号问题,最终AC。

虽然我代码写的很啰嗦,也很难懂,给自己做个留念吧。

 #include <stdio.h>
#include <string.h> #define max(a, b) ((a) >= (b) ? (a) : (b)) char A[];
char B[];
int C[];
int mark; char *revstr(char *str, size_t len)
{ char *start = str;
char *end = str + len - ;
char ch; if (str != NULL)
{
while (start < end)
{
ch = *start;
*start++ = *end;
*end-- = ch;
}
}
return str;
} void add(char A[], char B[]){ int i, lenA, lenB, len;
memset(C,,sizeof(C)); lenA = strlen(A);
lenB = strlen(B);
len = max(lenA, lenB); revstr(A,lenA);
revstr(B,lenB); A[lenA] = '';
B[lenB] = ''; for(i=;i<len+;i++){ C[i] = (A[i] - '') + (B[i] - '') ;
} for(i=;i<len+;i++){
if(C[i] > ){
C[i]%=;
C[i+]++;
}
} if(mark == ) putchar('-');
if(C[len]==){
for(i=len-;i>=;--i)
printf("%d", C[i]);
printf("\n");
} else {
for(i=len;i>=;--i)
printf("%d", C[i]);
printf("\n");
}
A[lenA] = '\0';
B[lenB] = '\0';
revstr(A,lenA);
revstr(B,lenB); } void minus(char A[], char B[]){ int i, lenA, lenB, len;
memset(C,,sizeof(C)); lenA = strlen(A);
lenB = strlen(B);
len = max(lenA, lenB);
revstr(A,lenA);
revstr(B,lenB); A[lenA] = '';
B[lenB] = ''; for(i=;i<len;i++){ C[i] = (A[i] - '') - (B[i] - '') ;
} for(i=;i<len;++i){
if(C[i] < ){
C[i] += ;
C[i+]--;
}
} if(mark == ) putchar('-'); for(;C[len]==;--len)
if(len==)
break;
for(i=len;i>=;--i)
printf("%d", C[i]);
printf("\n"); A[lenA] = '\0';
B[lenB] = '\0';
revstr(A,lenA);
revstr(B,lenB);
} int main(int argc, char const *argv[])
{
int t, i, lenA, lenB, len, Amark, Bmark; scanf("%d", &t);
while(t--){ mark = ;
Amark = ;
Bmark = ; memset(A,'',sizeof(A));
memset(B,'',sizeof(B)); scanf("%s", A);
scanf("%s", B); lenA = strlen(A);
lenB = strlen(B); int len;
len = max(lenA, lenB); if(A[] == '-'){
for(i=;i<lenA;++i)
A[i-]=A[i];
A[i-]='\0';
A[i] = '';
Amark = ;
} if(B[] == '-'){
for(i=;i<lenB;++i)
B[i-]=B[i];
B[i-]='\0';
B[i] = '';
Bmark = ;
} while(A[]== ''){
for(i=;i<lenA;++i)
A[i]=A[i+];
A[lenA]='';
} if(A[]=='\0'){
A[]='';
A[]='\0';
} while(B[]== ''){
for(i=;i<lenB;++i)
B[i]=B[i+];
B[lenB]=''; } if(B[]=='\0'){
B[]='';
B[]='\0';
} if(A[] == '' && B[] == ''){
printf("0\n");
printf("0\n");
continue;
} lenA = strlen(A);
lenB = strlen(B);
len = max(lenA, lenB); lenA = strlen(A);
lenB = strlen(B); if(Amark == && Bmark == ){
mark = ;
add(A,B); if(lenA>lenB){
mark = ;
minus(A,B);
}
else if(lenA < lenB){
mark = ;
minus(B,A);
}
else {
if(strcmp(A,B)>){
mark = ;
minus(A,B);
}
else if(strcmp(A,B)<){
mark = ;
minus(B,A);
}
else {mark = ;minus(A,B);}
}
continue;
} if(Amark == && Bmark ==){ mark = ;
add(A,B); if(lenA>lenB){
mark = ;
minus(A,B);
}
else if(lenA<lenB){
mark = ;
minus(B,A);
}
else {
if(strcmp(A,B)>){
mark = ;
minus(A,B);
}
else if(strcmp(A,B)<){
mark = ;
minus(B,A);
}
else{
minus(A,B);
}
}
continue;
} if(Amark == && Bmark == ){
if(lenA>lenB){
mark = ;
minus(A,B);
}
else if(lenA<lenB){
mark = ;
minus(B,A);
}
else {
if(strcmp(A,B)>){
mark = ;
minus(A,B);
}
else if(strcmp(A,B)<){
mark = ;
minus(B,A);
}
else{
mark = ;
minus(A,B);
}
} mark = ;
add(A,B);
continue;
} if(Amark == && Bmark == ){
if(lenA>lenB){
mark = ;
minus(A,B);
}
else if(lenA<lenB){
mark = ;
minus(B,A);
}
else{
if(strcmp(A,B)>){
mark = ;
minus(A,B);
}
else if(strcmp(A,B)<){
mark = ;
minus(B,A);
}
else {
mark = ;
minus(A,B);
}
}
mark = ;
add(A,B);
continue;
}
} return ;
}

SZU:B47 Big Integer I的更多相关文章

  1. SZU:B47 Big Integer II

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  2. LeetCode 7. Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...

  3. Integer.parseInt 引发的血案

    Integer.parseInt 处理一个空字符串, 结果出错了, 程序没有注意到,搞了很久, 引发了血案啊!! 最后,终于 观察到了, 最后的部分: Caused by: java.lang.NoC ...

  4. 由一个多线程共享Integer类变量问题引起的。。。

    最近看到一个多线程面试题,有三个线程分别打印A.B.C,请用多线程编程实现,在屏幕上循环打印10次ABCABC- 看到这个题目,首先想到的是解决方法是定义一个Integer类对象,初始化为0,由3个线 ...

  5. [LeetCode] Integer Replacement 整数替换

    Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...

  6. [LeetCode] Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  7. [LeetCode] Integer to English Words 整数转为英文单词

    Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...

  8. [LeetCode] Roman to Integer 罗马数字转化成整数

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  9. [LeetCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

随机推荐

  1. 【Socket规划】套接字Windows台C语言

    [编译环境]:Visual Studio 2013 这是服务端实现流程. #include<stdio.h> #include<stdlib.h> #include<wi ...

  2. KMP算法之从next[]到nextVal[] (转)

    前些日子写了一篇KMP算法的博文,浅谈数据结构之KMP(串中的模式匹配算法),在这片文章中,谈到了一个模式串K值的记录数组 next[],详细可看那篇文章,其实,前面定义的next[]数组是有一定缺陷 ...

  3. 小工具:内存监视器(SystemMonitor)

    卸了360之后,与之捆绑的加速球也没了.加速球可以查看剩余内存量,清理残留进程,有的时候不觉得这小玩意有多大作用,卸了之后才知道后悔. 加速球的替代方案比比皆是,如Windows自带的任务管理器,窗口 ...

  4. 交易应用-运行多个SQL声明

    事务具有原子性.要么不运行.要么全运行.一旦成功运行永久保存.而这些正是因为事务的原子性和对数据库的持久性形成的.下面是一个关于统一给数据库中的数据改动的批量操作,利用到事务. TODO:批量改动数据 ...

  5. crawler_java应用集锦9:httpclient4.2.2的几个常用方法,登录之后访问页面问题,下载文件_设置代理

    在工作中要用到android,然后进行网络请求的时候,打算使用httpClient. 总结一下httpClient的一些基本使用. 版本是4.2.2. 使用这个版本的过程中,百度很多,结果都是出现的o ...

  6. linux_安装 redis

    Installation Download, extract and compile Redis with: $ wget http://download.redis.io/releases/redi ...

  7. Objective-C马路成魔【12-分类和协议】

    郝萌主倾心贡献.尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助.欢迎给作者捐赠,支持郝萌主.捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 分类与协议 ...

  8. 【百度地图API】如何制作商圈地图?行政地图?

    原文:[百度地图API]如何制作商圈地图?行政地图? 摘要: 想要显示某一个区域,并且鼠标放上去,该区域就会变色.这时,你就需要巧用多边形覆盖物,和它的鼠标事件了! 快来看看去哪儿网的实例吧:http ...

  9. 给Notepad++ 加右键菜单带图标

    原文:给Notepad++ 加右键菜单带图标 从网上下载下来的Notepad++  http://download.tuxfamily.org/notepadplus/6.3.3/npp.6.3.3. ...

  10. C# 程序自动批量生成 google maps 的KML文件

    原文:C# 程序自动批量生成 google maps 的KML文件 google maps 的 KML 文件可以用于静态的地图标注,在某些应用中,我们手上往往有成百上千个地址,我们需要把这些地址和描述 ...