POJ 1503 Integer Inquiry(大数相加)

POJ1503-Integer Inquiry编程解题指南 POJ(北大在线作业系统,Peking University Online Judge)是一个面向大学生、编程爱好者的在线题库和评测系统,它提供了一个自由、开放、具有一定难度的编程练习平台。许多计算机科学与技术专业的学生以及从事IT行业的技术人员通过此平台来提高自己的编程能力,尤其是在算法和数据结构方面。POJ(Peking University Online Judge)是一个为编程爱好者提供在线编程练习的平台。 阅读详情

一、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.
二、题解
        这个题和之前2602有 Poj 2602 Superlong sums(大数相加) 异曲同工。但还是有要注意的部分,就是这里有前导的0,而且题目没说是否每个数的位数是否相同。还有数组的长度也比题目说明的要大,所以开数组的时候千万不要手下留情啊。这个题目我WA了还多次,可能是考虑的情况不够全面,对题目的要求没有完全弄明白。所以,虽然经过了几次的调试,几组测试数据都过了,但是还是没有AC。请大神指教。但当我一头雾水的时候呢,居然发现java有一种脑残解法,由于java 中自带的 BigInteger 类,这是个不可变的任意精度的整数。而且接受十进制的字符串,并能将 BigInteger 的十进制字符串表示形式转换为 BigInteger。所以,管它什么大数,都弱爆了。但是看来好东西虽然存在,但是了解它的原理还是必要的。
三、java代码
import java.util.*;   
import java.math.*;   
  
public class Main {   
  
    public static void main(String[] args) {   
        Scanner cin = new Scanner(System.in);   
        BigDecimal bd1 = BigDecimal.valueOf(0);   
        BigDecimal bd2 = BigDecimal.valueOf(0);   
        String str;   
           
        while(cin.hasNext()){   
            str = cin.nextLine();   
            if(str.equals("0"))   
                break;   
            else{   
                bd2 = new BigDecimal(str);   
                bd1 = bd1.add(bd2);   
            }   
        }   
           
        System.out.println(bd1.toPlainString());   
    }   
}  

求错误代码!!
import java.io.IOException;
import java.util.Scanner;

  public class Main {
	  static byte[] c = new byte[1000];  
      public static void add(String s1){
    	  int i;
          for (i = 0; i <s1.length(); i++){  
              c[i] += s1.charAt(i) - 48;  
          }  
          int cf = 0;  
          for (i = s1.length() - 1; i >= 0; i--) {  
              c[i] += cf;  
              cf=c[i]/10;  
              c[i]=(byte) (c[i] %10);  
          }  
      }
	  public static void main(String[] args) throws IOException {     
       Scanner cin = new Scanner(System.in);
       String s[]=new String[120];
       int i=0,j=0,k;
       String ss,te;
       String te2;
       int max=0;
       while(!(ss=cin.next()).equals("0")){
    	   s[i]=ss;
    	   max=Math.max(s[i].length(), max);
    	   i++;
       }
       for(k=0;k<i;k++){
    	   te=s[k];
    	   te2 ="";
    	   while(s[k].length()<max){
    		   s[k]+="0";
    		   te2+="0";
    	   }
    	   s[k]=te2+te;
    	   add(s[k]);
       }
       while(c[j]==0){
	    	j++;
	    }
       for(k=j;k<max;k++){
    	    System.out.print(c[k]);
       }
       System.out.println();
    }  
 }     
  
  
  
  
  
  
  


手把手教你用Wireshark国密版分析TLCP和IPSec协议(附下载地址) 本文详细介绍了Wireshark国密版在TLCP和IPSec协议分析中的实战应用,包括环境配置、协议解析、合规性检查及高级分析技巧。该工具针对商用密码算法(如SM2/SM3/SM4)进行了专项优化,支持GB/T 38636-2020 TLCP和GB/T 36968-2018 IPSec VPN等国家标准,帮助开发者与安全工程师高效完成密评分析任务。 阅读详情

相关推荐

新手必看!Unity中Tag和Layer的7个实际应用场景(含MOBA案例)

本文深入探讨Unity中Tag和Layer的7个实际应用场景,特别以MOBA游戏开发为例,详细解析如何利用LayerMask进行高效场景管理和碰撞检测优化。从双相机方案到射线检测的精准控制,帮助开发者掌握这些基础功能的进阶用法,提升游戏性能和开发效率。

weixin_28723171的博客 313

Integer Inquiry POJ - 1503(大数相加)

题目链接 题目大意: 给一些大数,求合 解题思路: 将数字当做字符串一位一位求。 (注意细节就OK,相当于模板题) 代码: #include <iostream> #include <cstdio> using namespace std; int ans[105]; int main(){ string St; while(cin>>S...

LiangNiuMu的博客 198

【数学建模】编程手学习路线

在学习过程中,建议注重理论与实践相结合,多进行实例练习和项目实践,以巩固所学知识并提升实际应用能力。同时,保持对新技术和新方法的关注和学习,不断提升自己的专业素养和竞争力。NumPy、Pandas、Matplotlib和Seaborn等库是数据处理和可视化的重要工具。掌握常用机器学习算法的原理和应用,如决策树、支持向量机、神经网络等。学习内容包括微积分、线性方程组、矩阵运算、概率分布、统计推断等。学习内容包括基本语法、函数和模块、面向对象编程、文件操作等。深入了解优化理论和方法,如梯度下降法、牛顿法等。

2301_79586491的博客 2962

poj1503 Integer Inquiry (大数相加)

C - Integer Inquiry Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1503 Appoint desc

苏苏爱自由 1866

基于CatBoost回归模型的完整预测分析:从建模到SHAP可解释性分析

本文介绍了使用CatBoost回归模型进行完整预测分析的流程。首先导入必要的Python库并加载数据,进行数据预处理包括训练测试集划分和归一化处理。然后通过网格搜索优化CatBoost超参数,使用最优参数训练模型并评估预测性能。结果显示模型具有较高的决定系数(R²=0.9944)和较低的误差指标(RMSE=0.0696)。接着进行残差分析和正态性检验,发现残差基本服从正态分布。最后通过SHAP分析实现模型可解释性,识别关键特征影响。该方法为梯度提升树在回归问题中的应用提供了完整解决方案。

fx666_的博客 747

【WILEY】从Revision到Online:逐层拆解投稿状态更新与关键文件提交实战

本文详细解析了学术论文从返修到在线发表的全过程,重点拆解了投稿系统状态更新背后的含义与应对策略。文章提供了返修稿与回复信的准备技巧、关键补充文件(如图文摘要)的提交要点,并分享了校对校样与处理出版协议的实战经验,帮助作者高效、专业地完成发表流程。

weixin_29209805的博客 713

POJ 1503 Integer Inquiry【大数相加 java】

Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26642   Accepted: 10325 Description One of the first users of BIT's new supercomputer was C

free斩 1315

# 解决 win11 连接共享打印机,报错 0x00000709 问题

# 解决 win11 连接共享打印机,报错 0x00000709 问题

段子手168的博客 9万+

POJ 1503 Integer Inquiry 简单大数相加

DescriptionOne 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

谙忆-陈浩翔 1974

S7-1200PLC与昆仑通态触摸屏以太网通信的具体方法和步骤(图文)

S7-1200PLC与昆仑通态触摸屏以太网通信的具体方法和步骤(图文)

Robot_PLC_HMI_Automation 1万+

lammps模拟石墨烯吸附水分子(gcmc)

本文分享lammps gcmc吸附的一个案例代码,上下壁面的通道材料为石墨烯,吸附的分子为tip4p水分子。大家好,我是小马老师。

lammps_jiayou的博客 2592

poj 1503 Integer Inquiry(大数相加)

problem link:http://poj.org/problem?id=1503 大数相加的一个题目。大数从末尾相加,倒序放入结果数组中。经过进制处理和去除多余的零后,正序输出结果数组。 AC code: #include&lt;iostream&gt; using namespace std; const int N=125; int sum[N+10],j;string s; ...

Light2Chasers的博客 236

四旋翼飞行器建模(一)

四旋翼飞行器的姿态运动学和姿态动力学建模方法。

加斯顿工程师的博客 686

poj 1503 Integer Inquiry

poj 1503 Integer Inquiry                    题目链接:http://poj.org/problem?id=1503 大数相加 题目大意:大数相加 题目分析:字符串处理 模拟  以下是代码:   #include #include #include using namespace std; int main() { int a[1000]={

slicer的技术交流栈 776

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

poj 1503 Integer Inquiry(多个大数相加)

poj 1503 Integer Inquiry(多个大数相加)

1254

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ-1503 Integer Inquiry-多个大数相加

Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31808   Accepted: 12404 Description One of the first users of BIT's new supercomputer was Chip

Some. 680

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

POJ – 1503 Integer Inquiry Integer Inquiry

POJ –1503 Integer Inquiry Integer Inquiry Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 34728 Accepted: 13523 Description One of the firstusers

emoheithree的博客 409

【原】 POJ 1503 Integer Inquiry 大整数加法 解题报告

http://poj.org/problem?id=1503 方法: 很简单,模拟手动加法过程, 结果中的前置0要消去 Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3...

ajiaxi111111的博客 131

C++高精度加乘类模板——POJ1503 Integer Inquiry

POJ_1503: Integer Inquiry Time Limit: 1000 MS Memory Limit: 10 MB 64bit IO Format: %I64d Submitted: 8 Accepted: 3 [Submit][Status][Web Board] Description One of the first users of BIT’s new superc...

WUST_cws的博客 246

POJ1503-Integer Inquiry

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 提示:就是多个大数相加的问题= = //Memory Time //184K 0MS ...

ζёСяêτ - 小優YoU 4228

POJ--1503:Integer Inquiry 大数加法

题目源地址:http://poj.org/problem?id=1503 程序源代码:

酒酿小圆子呀~ 839

poj 1503 Integer Inquiry (高精度运算)

题目链接:http://poj.org/problem?id=1503 思路分析:基本的高精度问题,使用字符数组存储然后处理即可。 代码如下: #include <iostream> #include <string> using namespace std; const int M = 100 + 10; char input[M]...

aqjh9999的博客 133

POJ 1053 Integer Inquiry && HDOJ 1047 Integer Inquiry (大数加法)

题目链接(POJ):http://poj.org/problem?id=1503 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions

MummyDing's Blog 1364

poj1503 Integer Inquiry(大数)

用的模板 直接贴代码 #include <vector> #include <iostream> #include <cstring> #include <iomanip> #include <string> #include <algorithm> using namespace std; //大数 struct BigInteger { static const int BASE = 100000000; //和WID

For_ACM的博客 238
上一篇: Poj1062 昂贵的聘礼 (dijkstra算法)
下一篇: 广度优先搜索(BFS)
TaiSung
博客等级 码龄15年 49粉丝 132原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值