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. Node.js 开发指南笔记

    第一章:node简介 介绍了node是什么:node.js是一个让javascript运行在服务器端的开发平台, node能做些什么:[书上的] 具有复杂逻辑的网站 基于社交网络的大规模Web应用 W ...

  2. 多普勒失真信号采样Matlab模拟分析

    多普勒失真信号采样Matlab模拟分析 方案 水声通信指的是使用声信号在水中数据传输. 相对而言.电磁信号在水中吸收严重衰减过快,光信号受水中悬浮颗粒的影响,也无法完毕远距离传输. 这两种信号的传播距 ...

  3. C#:winform项目在win7,xp32位和64位都能执行

    vs中项目配置管理器活动解决方式平台选择X86平台.

  4. NYOJ 105 其余9个

    九的余数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描写叙述 如今给你一个自然数n,它的位数小于等于一百万,如今你要做的就是求出这个数整除九之后的余数. 输入 第一行有一 ...

  5. HDU 4932 Miaomiao&#39;s Geometry(推理)

    HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...

  6. oracle_constraint的用处

    ql中constraint主要是增加约束 这个主要就是增加约束的 以下几种约束 .并 一一列举: 1.主键约束: 主键约束:就是对一个列进行了约束,约束为(非空.不重复)要对一个列加主键约束的话,这列 ...

  7. 2014鞍山直播比赛H称号HDU5077(DFS修剪+通过计)

    NAND Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Sub ...

  8. [ Alcatraz ]管理Xcode插件

    [ Alcatraz 配置 ] 1.包管理器在线安装 Terminal终端 $ curl -fsSL https://raw.githubusercontent.com/supermarin/Alca ...

  9. STL慎重选择删除元素的

     一.要删除容器中有特定值的全部对象 1.假设容器是vector.string或deque.则使用erase-remove习惯使用方法.比如: vector<int> c; c.era ...

  10. 解决Uploadify上传控件加载导致的GET 404 Not Found问题

    今天在项目发用到Uploadify上传, 发现在打开页面时会有一多余的请求,由于路由没有设置这个,导致404错误,能搜索查到以下解决的方法 <Uploadify v3 bug. Unecessa ...