## HDU1002 : A + B Problem II

A + B Problem II

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 367113 Accepted Submission(s): 71500

Problem Description

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

Output

For each test case, you should output two lines. The first line is “Case #:”, # means the number of the test case. The second line is the an equation “A + B = Sum”, Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input

2
1 2
112233445566778899 998877665544332211

Sample Output

Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

``````#include
#include
#include
#include
#include
using namespace std;

int m3[100002];
int f = 1;

void Reverse(char *word,int len)   // 反转数字
{
char temp;
int i, j;
for (j = 0, i = len - 1; j < i; --i, ++j) {
temp = word[i];
word[i] = word[j];
word[j] = temp;
}
}

int check(int a[],int num)      //归整
{  int k=0,len=num;
while(a[len-1]==0&&len>1) len--;    //去掉前导0
for(k=0; kif(a[k]>=10)
{
a[k+1]=a[k+1]+ a[k]/10;  a[k]=a[k] % 10;
}
if (a[k]!=0) len=k+1;  //确定数组最终长度
return len;
}

int addition(int m3[], char m1[], int num1, char m2[], int num2)
{
int i,len1,len2,len;
len1=num1;
len2=num2;
len=(len1>=len2)?len1:len2;     //定位数

for(i=0; i<=len; i++) m3[i]=0;   //初始化
for (i=len1; i1; i++) m1[i]='0'; //缺位前导补0
m1[i] = '\0';
for (i=len2; i1; i++)    m2[i]='0';
m2[i] = '\0';
Reverse(m1,len1);
Reverse(m2,len2);
for (i=0; i<=len; i++)
m3[i]=(int)(m1[i]-'0'+m2[i]-'0');   //加法
len=check(m3,len);
return len;
}

int Fun(char a[]){   //确定位数
int i = 0;
for(i = 0; a[i] != '\0'; i++);
return i;  //精确位数
}

int main(){
char num1[100001],num2[100001];
int m,len1,len2,len;
cin >> m;
while(m--){
cin >> num1 >> num2;
len1 = Fun(num1);
len2 = Fun(num2);
if(f != 1){
cout << endl;
}
cout << "Case " << f << ":" << endl;
cout << num1 << " + " << num2 << " = ";
for(int i = len -1; i >= 0; i--){
cout << m3[i];
}
cout << endl ;
f++;
}
return 0;
}``````

## Open Judge2748:全排列

s1 = t1, s2 = t2, …, sp - 1 = tp - 1, sp < tp成立。

abc

abc
acb
bac
bca
cab
cba

``````#include
#include
#include
#include  //在后面使用memset函数和strlen需要包含这个头文件
using namespace std;

const int N=7;
char str[N];
char result[N];
int isVisit[N];
int num = 0;

void PutStr(int n){
if(n == num){
cout << result << endl;
return ;
}
for(int i = 0; i < num; i++){
if(isVisit[i] == 0){
isVisit[i] = 1;
result[n] = str[i];
PutStr(n + 1);  //开始递归
isVisit[i] = 0;
}
}
}

int main(){
memset(result,0,sizeof(result));  //初始化操作
memset(isVisit,0,sizeof(isVisit));
while(cin >> str){
num = strlen(str);
PutStr(0);
cout << endl;
}
return 0;
}``````