⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2323.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 2323 on 2006-08-20 at 21:30:54 */ 
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
 
const int N = 128;
 
class BigInt {
public:
	int n[N], len;
	BigInt();
	void operator +=(const BigInt&);
	void print() const;
};
BigInt::BigInt() {
	char w[N]; scanf("%s", w);
	len = strlen(w);
	memset(n, 0, sizeof(n));
	for(int i = 0; i < len; i++)
		n[len-i-1] = w[i] - '0';
	while(len > 1 && n[len-1] == 0) len--;
}
void BigInt::operator +=(const BigInt& b) {
	len >?= b.len;
	int r = 0;
	for(int i = 0; i < len; i++) {
		n[i] += b.n[i]+r;
		r = n[i]/2; n[i] %= 2;
	}
	while(r != 0) { n[len++] = r; r /= 2; }
}
void BigInt::print() const {
	for(int i = len-1; i >= 0; i--)
		printf("%d", n[i]);
	putchar('\n');
}
 
int main()
{
	int T;
	
	scanf("%d", &T);
	for(int t = 1; t <= T; t++) {
		BigInt a, b;
		a += b;
		printf("%d ", t);
		a.print();
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -