杭电 HDU 4608 I-number
http://acm.hdu.edu.cn/showproblem.php?pid=4608
最高位进位,导致我提交全是WA,所以我用的数组存数据,而且是倒着存,即个位在x[0]处,这样存有个好处就是进位时不需要对整个数组
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; char x[100010],b[100010]; int main()
{
int t,d,i,n,p;
scanf("%d",&t);
while(t--)
{
memset(x,0,sizeof(x));
scanf("%s",&b);
n = strlen(b);
for(i = 0; i < n; i++)
{
x[n-1-i] = b[i];
}
n = strlen(x);
// printf("n:%d\n",n);
p = 1;
while(p%10!=0)
{
p=d=0;
x[0] += 1;
// printf("%c ",x[n-1]);
while(x[0+d] > '9') //处理进位
{
x[0+d] = '0';
d++;
if(d==n) //如果最高位再进位后更新长度并使新的最高位数为1
{
x[0+d] = '1';
n++;
}
else
{
x[0+d] += 1;
}
// printf("d:%d n:%d",d,n);
}
for(i = 0; i < n; i++)
{
p += (int)(x[i]-'0');
}
}
// printf("\n");
for(i = n-1; i >= 0; i--)
{
printf("%c",x[i]);
}
printf("\n");
} return 0;
}
杭电 HDU 4608 I-number的更多相关文章
- 杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)
欢迎"热爱编程"的高考少年--报考杭州电子科技大学计算机学院 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memor ...
- 杭电 HDU ACM Milk
Milk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 深搜基础题目 杭电 HDU 1241
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...
- 杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...
- 杭电 HDU 1031 Design T-Shirt
Design T-Shirt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 杭电 HDU 2717 Catch That Cow
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 杭电 HDU 1279 验证角谷猜想
验证角谷猜想 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- ACM 杭电HDU 2084 数塔 [解题报告]
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
随机推荐
- UESTC_Little Deer and Blue Cat CDOJ 1025
In DOTA, there are two Intellegence heroes. One is Enchantress, who is usually called Little Deer by ...
- 解决mongodb连接失败问题
错误提示: MongoDB shell version: 2.4.9 connecting to: test Mon Mar 3 23:45:09.491 Error: couldn't conne ...
- tr转换或删除字符
字符处理命令:tr —— 转换或删除字符 逐个字符处理而不是处理单词的tr [OPTION]... SET1 [SET2] -d: 删除出现在字符集中的所有字符 tr ab AB
- Maven引入hadoop依赖包出错解决办法
错误: ArtifactTransferException: Failure to transfer org.apache.hadoop:hadoop-hdfs:jar:2.6.0 from http ...
- Can you solve this equation?(二分)
Can you solve this equation? Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Ja ...
- ACM学习-POJ-1125-Stockbroker Grapevine
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1125-Stockbroker Grapevine Stockbroker Grapevine Time Li ...
- 百度地图坐标转换API和地图API
利用百度地图的服务将经纬度转换为米单位坐标 using System; using System.Collections.Generic; using System.Linq; using Syste ...
- Linux操作系统报:read-only file system
在对集群测试过程中发现系统中某一节点中的磁盘变成read-only file system,从而导致测试任务出错,从网上查找资料,找到以下解决方案: 这个报错的意思是硬盘属性变成只读,不可写入: VO ...
- Mysql自定义变量的使用
用户自定义变量是一个容易被遗忘的MySQL特性,但是如果能用的好,发挥其潜力,在某些场景可以写出非常高效的查询语句.在查询中混合使用过程化和关系化逻辑的时候,自定义变量可能会非常有用.单纯的关系查询将 ...
- margin-top失效及解决办法
现象:当两个空的块级元素嵌套时,如果内部的块设置有margin-top属性,而且父元素没有下边解决方法所述的特征,那么内部块的margin-top属性会绑架父元素(即将margin-top传递凌驾给了 ...