hdu 4608 I-number 大整数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4608
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#define maxn 105000
using namespace std; int len;
char a[maxn],b[maxn]; int getsum(){
int ans = ; //printf("%d\n",len);
for(int i=;i<len;i++){
ans += a[i] - '';
}// printf("ans %d\n",ans);
return ans;
}
void add(int num){
int incnt = ;
int temp = a[] - '' + num; //printf("temp %d\n",temp); if(temp > ){
incnt = ;
a[] = temp - + ''; //printf("*** %c %d\n",a[0],temp);
}
else a[] = temp + '';
int cnt = ;
while(incnt && cnt < len){
temp = a[cnt] - '' + incnt;
if(temp>){
incnt = ;
a[cnt] = temp - + '';
}
else {incnt = ; a[cnt] = temp + '';}
cnt++;
}
if(incnt && cnt == len){
a[cnt] = '';
len ++;
}
} int main()
{
//if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int T;
cin>>T;
while(T--){ int numzero = ;
scanf("%s",b); while(b[numzero] == ''){
numzero++;
} int cnt = numzero;
len = ;
for(int i=;b[cnt]!='\0';i++) {a[i] = b[cnt++]; len++; } for(int i=;i<len/;i++){
int temp = a[i];
a[i] = a[len--i];
a[len--i] = temp;
}
int sum = getsum()%; //printf("%d %d\n",len,sum);
if(sum == ) sum = ;
int time = ;
while(sum != && time < ){
add(); //printf("%d %d\n",len,sum);
sum = getsum()%;
time++;
}
while(numzero--) printf("");
for(int i=len-;i>=;i--) printf("%c",a[i]);
printf("\n");
}
}
hdu 4608 I-number 大整数的更多相关文章
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 1024 Palindromic Number int_string转换 大整数相加
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT A1024 Palindromic Number (25 分)——回文,大整数
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- hdu 1316(大整数)
How Many Fibs? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- [转载]JavaScript 中小数和大整数的精度丢失
标题: JavaScript 中小数和大整数的精度丢失作者: Demon链接: http://demon.tw/copy-paste/javascript-precision.html版权: 本博客的 ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- HDOJ-1002 A + B Problem II (非负大整数相加)
http://acm.hdu.edu.cn/showproblem.php?pid=1002 输入的数都是正整数,比较好处理,注意进位. //非负大整数加法 # include <stdio.h ...
- 自己动手写Java大整数《3》除法和十进制转换
之前已经完毕了大整数的表示.绝对值的比較大小.取负值.加减法运算以及乘法运算. 详细见前两篇博客(自己动手写Java * ). 这里加入除法运算. 另外看到作者Pauls Gedanken在blog( ...
- Java 实现大整数加减乘除
自己用Java实现的大整数加减乘除运算.还有可以改进的地方,有兴趣的童鞋可以加以改进.仅供参考,请勿转载! package barrytest; import java.util.ArrayList; ...
随机推荐
- EntityFrameowk6.1 使用enum和低版本的不同
原有项目中使用EF5.0 实体类 public partial class Log : BaseEntity { public Nullable<int> LogLevelId { get ...
- while read line无法循环read文件
while read line 与for循环的区别 例子:要从一个ip列表中获取ip.port,然后ssh ip 到目标机器进行特定的command操作ssh -o StrictHostKeyChec ...
- 解决ubuntu下的文本编辑器gedit的乱码问题
缺省配置下,用 Ubuntu 的文本编辑器(Gedit)打开GB18030(繁体中文用户请将这里的出现的GB18030替换成BIG5或BIG5-HKSCS)类型的中文编码文本文件时,将会出现乱码. 出 ...
- undefined与null的区别(待修整)
没有实体的对象称为空对象.只用对象的引用,而不存在引用的实体对象 就叫做空对象 在常见的强类型语言中,通常有一个表示"空"的值,比如NULL.但是在Javascript中,空(或者 ...
- js实现滑动解锁功能(PC+Moblie)
http://dummyimage.com/600x400/ http://placehold.it/140x70 实现效果: css样式代码略. html代码: 页面上导入了jquery.mobil ...
- PHP中定义常量的几种方式与区别
[问]在php中定义常量时,const与define的区别? [答]使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很 ...
- 功能: 用函数 funName 对数组 objArray 中的每个值进行处理一次,
function each( objArray, funName ) {//功能: 用函数 funName 对数组 objArray 中的每个值进行处理一次,for(var i=0; i<obj ...
- phpcms 标签解析
phpcms 每个pc标签对应modules控制器下一个 tag.class类 比如 {pc:content action="position" posid="2&quo ...
- HDU 1069 Monkey and Banana(LIS最长上升子序列)
B - LIS Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descripti ...
- 英语学习App演示