POJ 1503
http://poj.org/problem?id=1503
对于这个题我也是醉了,因为最开始是有学长和我们说过这个题目的,我以为我记得题目是什么意思,也就没看题目,结果按案例去理解题意,结果WA了一晚上,我也是醉醉哒。
最后今天才在discuss发现是我的理解题意错了,改下,就对了。给我一个很大的教训。。。。。
题意很简单,,就是一组大整数的加法而已,终止的标志就是只有一个0输入。
#include <stdio.h>
#include <string.h> char str[]={};
int a[]={},sum[]={}; int main()
{
while(scanf("%s",str)&&strcmp(str,"")){
int len=strlen(str);
for(int i=,j=len-;i<len;i++,j--) //我用一个a数组的目的就是反正前导0的出现。因为我的数据是从开始到末尾是倒过来的,所以前导0在之后的加法中也是在后面了,不起任何作用。
a[i]=str[j]-'';
for(int i=;i<=;i++){
sum[i]+=a[i];
if(sum[i]>=) {
sum[i+]++;
sum[i]-=;
}
}
memset(str,,sizeof(str)); //初始化,反正之后的str数组较小,只替代了部分之前的str数组。
}
for(int i=,j=;i>;i--){
if(sum[i]==) {
j--;
}
if(i!=j)printf("%d",sum[i]);
}
printf("%d\n",sum[]);
return ;
}
POJ 1503的更多相关文章
- POJ 1503 Integer Inquiry 大数 难度:0
题目链接:http://poj.org/problem?id=1503 import java.io.*; import java.math.BigInteger; import java.util. ...
- Poj 1503 Integer Inquiry
1.链接地址: http://poj.org/problem?id=1503 2.题目: Integer Inquiry Time Limit: 1000MS Memory Limit: 1000 ...
- poj 1503 Integer Inquiry (高精度运算)
题目链接:http://poj.org/problem?id=1503 思路分析: 基本的高精度问题,使用字符数组存储然后处理即可. 代码如下: #include <iostream> # ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- POJ 1503 Integer Inquiry(大数相加,java)
题目 我要开始练习一些java的简单编程了^v^ import java.io.*; import java.util.*; import java.math.*; public class Main ...
- POJ 1503 Integer Inquiry 简单大数相加
Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his explo ...
- poj 1503 大数相加(java)
代码: import java.math.*; import java.util.Scanner; public class Main { public static void main(String ...
- POJ 1503 大整数
之前做的大整数,都是一位一位操作. 优化方案:压缩方案. 模板: + - * 操作符重载 #include<cstdio> #include<iostream> #inclu ...
- poj 1503 高精度加法
把输入的数加起来,输入0表示结束. 先看我Java代码,用BigINteger类很多东西都不需要考虑,比如前导0什么的,很方便.不过java效率低点,平均用时600ms,C/C++可以0ms过. im ...
随机推荐
- CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)
CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: /etc/init.d/iptables stop #关闭防火墙 关闭SELINUX vi /etc/sel ...
- Effective Objective-C 2.0 — 第二章 对象、消息、运行期 - 第六条:理解“属性”这一概念
开发者通过对象来 存储并传递数据. 在对象之间传递数据并执行任务的过程就叫做“消息传递”. 这两条特性的工作原理? Objective-C运行期环境(Objective-C runtime) ,提供了 ...
- yii2 如何用命名空间方式使用第三方类库
原文地址:http://www.yiichina.com/tutorial/395 Yii 2.0最显著的特征之一就是引入了命名空间,因此对于自定义类的引入方式也同之前有所不同.这篇文章讨论一下如何利 ...
- Idea修改js和jsp不用重启
- java批量生成excel代码分享
package com.test.util; /** * @author ocq * */ import java.io.FileOutputStream; import java.io.IOExce ...
- asp.net core csrf
如果用tag 比如 <form asp-action="Login" asp-controller="Account" method="post ...
- hdu4782 Beautiful Soup (模拟)
http://acm.hdu.edu.cn/showproblem.php?pid=4782 2013成都区域赛全题PDF:http://acm.hdu.edu.cn/downloads/2013Ch ...
- 通过Canvas及File API缩放并上传图片完整示例
<!DOCTYPE html> <html> <head> <title>通过Canvas及File API缩放并上传图片</title> ...
- mysql 总结二(自定义存储过程)
mysql执行流程: sql命令--->mysql引擎-----(分析)---->语法正确-----(编译)--->可识别命令----(执行)---->执行结果---(返回)- ...
- PHP基础之 数组(二)
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...