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.

InputIn 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≤s≤101000).OutputFor 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

OJ-ID:
hdu-5920

author:
Caution_X

date of submission:
20191029

tags:
模拟

description modelling:
给定一个数n,把n拆成若干个数相加,且这若干个数是回文串
输出:输出拆成了多少个数以及每一个数的大小

major steps to solve it:
把一个数随机拆成两个回文串显然十分不现实。
我们可以把一个按照它所能拆的最大回文串来拆:n=n1(回文串)+n2
若n2不是回文串,n2代替n的位置继续拆出新数,若n2也是回文串,结束,输出答案。

warnings:
n=10特判

AC code:

#include<bits/stdc++.h>
using namespace std;
char num[],sub[];
char ans[][];
char one[]="";
bool judge(char *s){//判断当前数字是否为回文数字
int lens = strlen(s);
for(int i = ;i<lens/;i++){
if(s[i]!=s[lens - i - ]){
return false;
}
}
return true;
}
void decrease(char *s1,char *s2)
{
int len1=strlen(s1);
int len2=strlen(s2);
int i=len1-,j=len2-,flag=;
while(i>=&&j>=) {
if(s1[i]-''-flag>=) {
s1[i]-=flag;
flag=;
}
else {
s1[i] = s1[i] + - flag;
flag = ;
}
if(s1[i]>=s2[j]) {
s1[i]=s1[i]-s2[j]+'';
}
else {
s1[i]=s1[i]+-s2[j]+'';
flag=;
}
i--,j--;
}
while(i>=&&flag) {
if(s1[i]-''>=flag) {
s1[i]-=flag;
flag=;
}
else {
s1[i]=s1[i]+-flag;
flag=;
}
i--;
}
int id=;
bool pre_0=true;
char tmp[];
memset(tmp,,sizeof(tmp));
for(int k=;k<len1;k++) {
if(s1[k]==''&&pre_0) continue;
if(s1[k]!=''&&pre_0) pre_0=false;
tmp[id++]=s1[k];
}
if(!id) {
tmp[id++]='';
}
tmp[id]='\0';
strcpy(s1,tmp);
}
void palindromic(char *s1,char *s2)
{
int len1=strlen(s1),len2;
if(len1==&&s1[]==''&&s1[]==''){
s2[]='';
s2[]='\0';
return;
}
if(len1&) len2=len1/+;
else len2=len1/;
for(int i=;i<len2;i++) {
s2[i]=s1[i];
}
s2[len2]='\0';
decrease(s2,one);
if(s2[]=='') {
s2[]='';
}
for(int i=len1-,j=;j<i;j++,i--) {
s2[i]=s2[j];
}
s2[len1]='\0';
}
int main()
{
//freopen("input.txt","r",stdin);
int T,kase=;
scanf("%d",&T);
while(T--) {
scanf("%s",num);
int id=;
while(num[]!=''&&id<) {
if(judge(num)) {
strcpy(ans[id++],num);
break;
}
memset(sub,,sizeof(sub));
palindromic(num,sub);
strcpy(ans[id++],sub);
decrease(num,sub);
}
printf("Case #%d:\n%d\n",kase++,id);
for(int i=;i<id;i++) {
printf("%s\n",ans[i]);
}
}
}

D - Ugly Problem HDU - 5920的更多相关文章

  1. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  2. hdu-5920 Ugly Problem(贪心+高精度)

    题目链接: Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. Ugly Problem

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Spec ...

  4. hdu 5920(模拟)

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. Flow Problem HDU - 3549

    Flow Problem HDU - 3549 Network flow is a well-known difficult problem for ACMers. Given a graph, yo ...

  6. Prime Ring Problem HDU - 1016 (dfs)

    Prime Ring Problem HDU - 1016 A ring is compose of n circles as shown in diagram. Put natural number ...

  7. HDU - 5920 Ugly Problem 求解第一个小于n的回文数

    http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...

  8. HDU 5920 Ugly Problem

    说起这道题, 真是一把辛酸泪. 题意 将一个正整数 \(n(\le 10^{1000})\) 分解成不超过50个回文数的和. 做法 构造. 队友UHC提出的一种构造方法, 写起来比较方便一些, 而且比 ...

  9. HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛

    题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...

随机推荐

  1. A:mysql数据库章节导航

    mysql数据库章节导航 mysql5.7的安装(yum和二进制安装) 数据库的基本操作 索引 权限管理 日志管理 逻辑备份mysqldump 物理备份:xtrabackup 主从复制-传统方式 主从 ...

  2. R-6 线性回归模型流程

    本节内容: 0:小知识 1:新数据要如何进行分析 2:第二步骤:理解数据 3:第三步骤:相关分析 4:特殊点 0:小知识 0.1:我们说对分析一个数据一般是分步骤的:那么我们可以对其中的步骤进行打标签 ...

  3. 201871010116-祁英红《面向对象程序设计(java)》第十七周学习总结

    博文正文开头格式:(2分) 项目 内容 <面向对象程序设计(java)> https://home.cnblogs.com/u/nwnu-daizh/ 这个作业的要求在哪里 https:/ ...

  4. P3747 [六省联考2017]相逢是问候

    题意 如果对一个数操作\(k\)次,那么这个数会变成\(c^{c^{...^{a_i}}}\),其中\(c\)有\(k\)个. 根据P4139 上帝与集合的正确用法这道题,我们可以知道一个数不断变为自 ...

  5. vue 父子父组件通过props传父页面请求后的数据

    父子父组件通过props传父页面请求后的数据,则在父页面的子组件上加上判断数据是否存在即可,如下 <gl-line-bar v-if="oneWeekBetEcharts" ...

  6. 【xAsset框架】HFS 轻量级HTTP Server快速入门指南

    一.引子 最近马三有幸参与开发了一个简易轻量的Unity资源管理框架 xAsset ,xasset 提供了一种使用资源路径的简单的方式来加载资源,简化了Unity项目资源打包,更新,加载,和回收的作业 ...

  7. jupyter notebook改变行间图片大小

    jupyter notebook使用起来代码效果很直接,这是我最喜欢的一点,但是主题单一,后来改了一下主题.也可以接受了,但是还有一个问题是显示图片太小我们可以用两个方法来改变它. 一.可以通过rcP ...

  8. mybatis无效比较:invalid comparison:java.util.data and java.lang.string

    原因: 时间与空字符串比较是无效的,如果拿传入的时间类型参数与空字符串''进行对比则会引发invalid comparison:java.util.data and java.lang.string异 ...

  9. 以太坊智能合约开发 Solidity学习

    1. pragma solidity >=0.4.22 <0.6.0;//版本号,头文件 contract BooleanTest { bool _a;//默认返回false int nu ...

  10. MySQL逻辑控制语句的使用

    一.IF语句     1).   IF(expr1,expr2,expr3) 如果expr1为true则结果为expr2否则为expr3 -->相当于三元运算符                  ...