博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
阅读量:4313 次
发布时间:2019-06-06

本文共 2381 字,大约阅读时间需要 7 分钟。

Ugly Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0
Special Judge

Problem Description
Everyone hates ugly problems.
You are given a positive integer. You must represent that number by sum of palindromic numbers.
A palindromic number is a positive integer such that if you write out that integer as a string in decimal without leading zeros, the string is an palindrome. For example, 1 is a palindromic number and 10 is not.
 

 

Input
In the first line of input, there is an integer T denoting the number of test cases.
For each test case, there is only one line describing the given integer s (
1\leq s \leq 10^{1000}).
 

 

Output
For each test case, output “Case #x:” on the first line where x is the number of that test case starting from 1. Then output the number of palindromic numbers you used, n, on one line. n must be no more than 50. en output n lines, each containing one of your palindromic numbers. Their sum must be exactly s.
 

 

Sample Input
2
18
1000000000000
 
 
Sample Output
Case #1:
2
9
9
Case #2:
2
999999999999
1
 
Hint
9 + 9 = 18 999999999999 + 1 = 1000000000000
 
题目连接:

题意:将一个数拆成n(n<=50)个回文数的和。
代码:
#include
#include
#include
using namespace std;char s[2000];int ans[100][2000];int gg[100];int sub(int t,int len){ int i; for(i=len-1; i>=0; i--) { s[i]=s[i]-'0'-ans[t][i]; if(s[i]<0) { s[i]+=10+'0'; s[i-1]-=1; } else s[i]+='0'; } for(i=0; i
s[j]-'0') sign=0; else if(ans[t][j]
=0&&ans[t][i]<0) { ans[t][i]+=10; ans[t][i-1]-=1; i--; } for(i=pre,j=len-1; i<=j; i++,j--) ans[t][j]=ans[t][i]; if(ans[t][pre]==0) { ans[t][len-1]=9; gg[t]=pre+1; } } pre=sub(t,len); t++; } printf("Case #%d:\n",asd); printf("%d\n",t); for(i=0; i
View Code

转载于:https://www.cnblogs.com/GeekZRF/p/5931419.html

你可能感兴趣的文章
潜移默化学会WPF(技巧篇)--TextBox相关(一) - AYUI框架 - 博客园
查看>>
Quartz.Net进阶之七:QuartzNet其他的功能简述
查看>>
消息队列
查看>>
WPF进阶教程 - 使用Decorator自定义带三角形的边框
查看>>
SQLServer之FOREIGN KEY约束
查看>>
redis 系列2 知识点概述
查看>>
图像滤镜艺术---图像滤镜晕影调节算法研究
查看>>
Win8Metro(C#)数字图像处理--2.21二值图像腐蚀
查看>>
MVC5 + EF6 入门完整教程
查看>>
SQL Server如何在变长列上存储索引
查看>>
Replication的犄角旮旯(八)-- 订阅与发布异构的问题
查看>>
Sliverlight实例之 绘制扇形和环形图
查看>>
Visual Studio 2012使用水晶报表Crystal Report
查看>>
你不知道的 页面编码,浏览器选择编码,get,post各种乱码由来
查看>>
SQLSERVER PRINT语句的换行
查看>>
Windows 8.1 应用开发 – 触控操作
查看>>
PowerDesigner创建物理模型
查看>>
使用Git、Git GUI和TortoiseGit
查看>>
vue---canvas实现二维码和图片合成的海报
查看>>
检查项目里是否有IDFA的方法
查看>>