题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1047

Integer Inquiry

Description

One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers. 
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)

Input

The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).

The final input line will contain a single zero on a line by itself.

Output

Your program should output the sum of the VeryLongIntegers given in the input.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input

1
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0

Sample Output

370370367037037036703703703670

测模板的。。

  1 #include<algorithm>
  2 #include<iostream>
  3 #include<istream>
  4 #include<ostream>
  5 #include<cstdlib>
  6 #include<cstring>
  7 #include<cassert>
  8 #include<cstdio>
  9 #include<string>
 10 using std::max;
 11 using std::cin;
 12 using std::cout;
 13 using std::endl;
 14 using std::swap;
 15 using std::string;
 16 using std::istream;
 17 using std::ostream;
 18 struct BigN {
 19     typedef unsigned long long ull;
 20     static const int Max_N = 36000;
 21     int len, data[Max_N];
 22     BigN() { memset(data, 0, sizeof(data)), len = 0; }
 23     BigN(const int num) {
 24         memset(data, 0, sizeof(data));
 25         *this = num;
 26     }
 27     BigN(const char *num) {
 28         memset(data, 0, sizeof(data));
 29         *this = num;
 30     }
 31     void cls() { len = 0, memset(data, 0, sizeof(data)); }
 32     BigN& clean(){ while (len > 1 && !data[len - 1]) len--;  return *this; }
 33     string str() const {
 34         string res = "";
 35         for (int i = len - 1; ~i; i--) res += (char)(data[i] + '0');
 36         if (res == "") res = "0";
 37         res.reserve();
 38         return res;
 39     }
 40     BigN operator = (const int num) {
 41         int j = 0, i = num;
 42         do data[j++] = i % 10; while (i /= 10);
 43         len = j;
 44         return *this;
 45     }
 46     BigN operator = (const char *num) {
 47         len = strlen(num);
 48         for (int i = 0; i < len; i++) data[i] = num[len - i - 1] - '0';
 49         return *this;
 50     }
 51     BigN operator + (const BigN &x) const {
 52         BigN res;
 53         int n = max(len, x.len) + 1;
 54         for (int i = 0, g = 0; i < n; i++) {
 55             int c = data[i] + x.data[i] + g;
 56             res.data[res.len++] = c % 10;
 57             g = c / 10;
 58         }
 59         while (!res.data[res.len - 1]) res.len--;
 60         return res;
 61     }
 62     BigN operator * (const BigN &x) const {
 63         BigN res;
 64         int n = x.len;
 65         res.len = n + len;
 66         for (int i = 0; i < len; i++) {
 67             for (int j = 0, g = 0; j < n; j++) {
 68                 res.data[i + j] += data[i] * x.data[j];
 69             }
 70         }
 71         for (int i = 0; i < res.len - 1; i++) {
 72             res.data[i + 1] += res.data[i] / 10;
 73             res.data[i] %= 10;
 74         }
 75         return res.clean();
 76     }
 77     BigN operator * (const int num) const {
 78         BigN res;
 79         res.len = len + 1;
 80         for (int i = 0, g = 0; i < len; i++) res.data[i] *= num;
 81         for (int i = 0; i < res.len - 1; i++) {
 82             res.data[i + 1] += res.data[i] / 10;
 83             res.data[i] %= 10;
 84         }
 85         return res.clean();
 86     }
 87     BigN operator - (const BigN &x) const {
 88         assert(x <= *this);
 89         BigN res;
 90         for (int i = 0, g = 0; i < len; i++) {
 91             int c = data[i] - g;
 92             if (i < x.len) c -= x.data[i];
 93             if (c >= 0) g = 0;
 94             else g = 1, c += 10;
 95             res.data[res.len++] = c;
 96         }
 97         return res.clean();
 98     }
 99     BigN operator / (const BigN &x) const {
100         return *this;
101     }
102     BigN operator += (const BigN &x) { return *this = *this + x; }
103     BigN operator *= (const BigN &x) { return *this = *this * x; }
104     BigN operator -= (const BigN &x) { return *this = *this - x; }
105     BigN operator /= (const BigN &x) { return *this = *this / x; }
106     bool operator <  (const BigN &x) const {
107         if (len != x.len) return len < x.len;
108         for (int i = len - 1; ~i; i--) {
109             if (data[i] != x.data[i]) return data[i] < x.data[i];
110         }
111         return false;
112     }
113     bool operator >(const BigN &x) const { return x < *this; }
114     bool operator<=(const BigN &x) const { return !(x < *this); }
115     bool operator>=(const BigN &x) const { return !(*this < x); }
116     bool operator!=(const BigN &x) const { return x < *this || *this < x; }
117     bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
118 }res, temp;
119 istream& operator >> (istream &in, BigN &x) {
120     string src;
121     in >> src;
122     x = src.c_str();
123     return in;
124 }
125 ostream& operator << (ostream &out, const BigN &x) {
126     out << x.str();
127     return out;
128 }
129 int main() {
130 #ifdef LOCAL
131     freopen("in.txt", "r", stdin);
132     freopen("out.txt", "w+", stdout);
133 #endif
134     int t;
135     char buf[200];
136     scanf("%d", &t);
137     while (t--) {
138         while (~scanf("%s", buf) && strcmp(buf, "0")) {
139             if (!strcmp(buf, "")) continue;
140             temp = buf, res = res + temp, temp.cls();
141         }
142         cout << res << endl;
143         if (t) cout << endl;
144         res.cls();
145     }
146     return 0;
147 }

View Code

转载于:https://www.cnblogs.com/GadyPu/p/4542010.html

hdu 1047 Integer Inquiry相关推荐

  1. HDU 1047 Integer Inquiry( 高精度加法水 )

    链接:传送门 思路:高精度水题 /*************************************************************************> File ...

  2. HDOJ 1047 Integer Inquiry

    JAVA睑板.... Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  3. Poj 1503 Integer Inquiry

    1.链接地址: http://poj.org/problem?id=1503 2.题目: Integer Inquiry Time Limit: 1000MS   Memory Limit: 1000 ...

  4. HDU 6441Find Integer

    题目链接                                             Find Integer Time Limit: 2000/1000 MS (Java/Others) ...

  5. HDU 2983 Integer Transmission

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2983 题意:将一个n位的数发送,每一位的发送时间为i,但是网络有延迟d,收到时顺序可能会变,求总共有多少种 ...

  6. ZOJ 1292 Integer Inquiry

    https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364791 题意:先输入一个数  表示测试样例的个数,接着输入几个数(可以不 ...

  7. hdu Find Integer (6441)(大费马定理)

    题目大意为,给你 a,n 的值,让你找出是否有 b,c 满足方程 an + bn = cn ,典型的定理内容.long long型一一寻找即可: #include<stdio.h> int ...

  8. Integer Inquiry

    java大数加法 import java.io.*; import java.math.*; import java.util.*;public class Main {public static v ...

  9. Java Java Java

    学下java 的大数该怎么用>< hdu 1023 Train Problem II 求 卡特兰 数 诶...不记得卡特兰数的我眼泪掉下来 第一次用 java 大数 有点激动...> ...

最新文章

  1. 3.C#中泛型类的进一步探讨
  2. 心目中的编程高手zz, 有点academic风格的说^_^
  3. 数据结构和算法:全面的算法代码库
  4. 深度学习入门篇--手把手教你用 TensorFlow 训练模型
  5. [-] Handler failed to bind to x.x.x.x:port排错
  6. php网站xml链接,xml图像超链接的制作代码
  7. 【软件测试】黑盒测试の因果图法
  8. 【C语言】第八章 地址操作与指针 题解
  9. RabbitMq学习笔记006---修改RabbitMq端口号和心跳时间
  10. 光通量发光强度照度亮度关系_照度、强光、光通量之间是什么关系
  11. 如何使用pattern recognition letter 的word写作模板
  12. 【ANSYS命令流】结构分析单元与材料模型
  13. 前端 - base64原理浅析
  14. 2020年最完整的ftp搭建教程-亲测可用
  15. SteamSDK发布更新
  16. 智慧食堂安全管控系统解决方案
  17. 一键抓取网页的所有图片
  18. PCI驱动框架简单分析
  19. 万恶的错误代码0xc000000e
  20. html 苏宁首页,简单实现

热门文章

  1. 文本框灰色文字提示,鼠标点击文字消失
  2. Qt入门(3)——信号和槽
  3. beaglebone black 联网
  4. 如果使用StateServer或SQLServer,会遇到的问题。。。。
  5. 关于win10更新后谷歌浏览器打开卡慢或者无法上网的问题解决
  6. ubuntu 挂在smb服务器的方法
  7. Android 4.4.2 动态添加JNI库方法记录 (一 JNI库层)
  8. [目录]Linux 核心系统命令目录
  9. S8 Linux磁盘与文件系统管理命令
  10. 8-5 Navicat工具与pymysql模块