杭电 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 ...
随机推荐
- Populating Next Right Pointers in Each Node 解答
Question Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLink ...
- poj 2723 Get Luffy Out(2-sat)
Description Ratish is a young man who always dreams of being a hero. One day his friend Luffy was ca ...
- Java Base64编码与图片互转
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...
- android面试题之五
二十六.什么情况会导致Force Close ?如何避免?能否捕获导致其的异常? 抛出运行时异常时就会导致Force Close,比如空指针.数组越界.类型转换异常等等. 捕获:可以通过logcat查 ...
- nand烧写分析/内核在启动过程中式如何将这个文件映射成/目录及各子目录的?
我用的是ramdisk.image.gz,烧写在flash的0x10140000处 我不太明白内核在启动过程中式如何将这个文件映射成/目录及各子目录的? 如果ramdisk.image.gz在flas ...
- GTID复制报错处理:Last_Error: Error 'Can't drop database 'test'; database doesn't exist' on query
创建GTID主从连接: mysql, master_user; 报错显示: Slave_IO_Running: Yes Slave_SQL_Running: No Last_Error: Error ...
- 【转换模型+扫描线】【UVA1398】Meteor
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- ADO.net基础学习总结(二)
将连接字符串放入配置文件中 1.添加一个“应用程序配置文件:app.config” <?xml version="1.0" encoding="utf-8" ...
- B - 敌兵布阵 线段树的点
B - 敌兵布阵 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descriptio ...
- Mysql自定义变量的使用
用户自定义变量是一个容易被遗忘的MySQL特性,但是如果能用的好,发挥其潜力,在某些场景可以写出非常高效的查询语句.在查询中混合使用过程化和关系化逻辑的时候,自定义变量可能会非常有用.单纯的关系查询将 ...