Pairs of Integers

You are to find all pairs of integers such that their sum is equal to the given integer number N and the second number results from the first one by striking out one of its digits. The first integer always has at least two digits and starts with a non-zero digit. The second integer always has one digit less than the first integer and may start with a zero digit.

Input

The input consists of a single integer N (10 ≤ N ≤ 10 9).

Output

Write the total number of different pairs of integers that satisfy the problem statement. Then write all those pairs. Write one pair on a line in ascending order of the first integer in the pair. Each pair must be written in the following format:
X + Y = N
Here XY, and N must be replaced with the corresponding integer numbers. There should be exactly one space on both sides of '+' and '=' characters.

Example

input output
302
5
251 + 51 = 302
275 + 27 = 302
276 + 26 = 302
281 + 21 = 302
301 + 01 = 302

//题意是,给出一个数,问有哪些数少掉某一位,与原数相加可得这个数,列出所有情况,第一个加数不能有前导 0 ,后一个可以有,

还有,重复的情况只能输出一个 比如 455 + 55 = 510 去掉 455 第一个5,和第二个5都能得510 ,只要输出一次就可以了

//做过类似的题目,用数学方法做,比较快。http://www.cnblogs.com/haoabcd2010/p/5991009.html

不过这题有点不一样,要按第一个数大小排序,还要去掉重复的,还要记得在第二个加数可能要补0 ,不过这都是些小问题。。。

15ms 比较快

 #include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std; struct Num
{
int a,b;
int z;
}num[];
int t; bool cmp(Num x,Num y)
{
return x.a<y.a;
} void read(int x,int y)
{
int a=x,b=y;
int lenx=,leny=;
while (a!=)
{
lenx++;
a/=;
}
while (b!=)
{
leny++;
b/=;
}
if (y==) leny=;
num[t].a=x;
num[t].b=y;
num[t].z=lenx--leny;
t++;
} int main()
{
int N;
while (scanf("%d",&N)!=EOF)
{
t=;
for (int i=;i<=N;i*=)
{
int a=N/i/;
int b=N/i%; if (b<)
{
int c=(N-N/i*i)/;
if ((*a+b)*i+*c==N)
read( (*a+b)*i+c , a*i+c );
}
b--;
if (a+b&&b>=)
{
int c=(N-N/i*i+i)/;
if ((*a+b)*i+*c==N)
read( (*a+b)*i+c , a*i+c );
}
}
sort(num,num+t,cmp);
int real_t=;
for (int i=;i<t;i++)
{
if (i!=&&num[i].a==num[i-].a) continue;
real_t++;
}
printf("%d\n",real_t);
for (int i=;i<t;i++)
{
if (i!=&&num[i].a==num[i-].a) continue;
printf("%d + ",num[i].a);
for (int j=;j<num[i].z;j++)
printf("");
printf("%d = %d\n",num[i].b,N);
}
}
return ;
}

Pairs of Integers的更多相关文章

  1. POJ 1117 Pairs of Integers

    Pairs of Integers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4133 Accepted: 1062 Des ...

  2. 2018牛客网暑期ACM多校训练营(第一场) J - Different Integers - [莫队算法]

    题目链接:https://www.nowcoder.com/acm/contest/139/J 题目描述  Given a sequence of integers a1, a2, ..., an a ...

  3. Different Integers 牛客多校第一场只会签到题

    Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, r2), ..., (lq, r ...

  4. 牛客暑假多校第一场J-Different Integers

    一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...

  5. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  6. Codeforces Round #562 (Div. 2) B. Pairs

    链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...

  7. Different Integers 牛客网暑期ACM多校训练营(第一场) J 离线+线状数组或者主席树

    Given a sequence of integers a1, a2, ..., an and q pairs of integers (l 1, r1), (l2, r2), ..., (lq, ...

  8. Different Integers

    牛客一 J题 树状数组 题目描述 Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, ...

  9. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

随机推荐

  1. OpenSessionInViewFilter的配置

    OpenSessionInViewFilter是用来处理懒加载异常的. 懒加载异常的意思的就是:还用不到的东西,就先不加载,等需要的时候再来加载. 所以懒加载对性能有一定的提升,但是,这也会出现一些问 ...

  2. Linux下自动监测并重启Apache服务脚本

    为了达到一个高可用的基于Apache的网站环境,在Apache由于种种原因自动停止运行之后,想立即恢复网站访问,这就需要有个工具实时监测Apache的运行状态并能够自动重启httpd服务,写了一个简单 ...

  3. 关于Docker&kubernetes的一些问题

    本文是我自己在学习docker以及kubernetes的过程中遇到的一些问题,以及同事在听过培训之后一些问题,事后我自己去网上找些资料以及问一些资深大牛,我在此做一个归纳总结,将这些问题的解答做一个分 ...

  4. mybatis部分版本异常invalid comparison: java.util.Date and java.lang.String

    严重: Servlet.service() for servlet [spring] in context with path [] threw exception [Request processi ...

  5. 往MySQL数据库datetime类型字段中插入数据库的当前时间

    代码: StringBuilder sb = new StringBuilder(); sb.append(" insert into uosdetailfile ("); sb. ...

  6. Linux网络编程中tcp_server和tcp_client函数的封装

    本文的主要目的是将server套接字和client套接字的获取,做一个简易的封装,使用C语言完成.   tcp_server   服务器端fd的获取主要分为以下几步: 1.创建socket,这一步仅仅 ...

  7. Hdu 2243 考研路茫茫——单词情结 (AC自己主动机+矩阵)

    哎哟喂.中文题. . .不说题意了. 首先做过POJ 2778能够知道AC自己主动机是能够求出长度为L的串中不含病毒串的数量的. POJ 2778的大概思路就是先用全部给的病毒串建一个AC自己主动机. ...

  8. react-native 极光推送(jpush-react-native)

    极光推送官方支持的 React Native 插件 安装 npm install jpush-react-native --savenpm install jcore-react-native --s ...

  9. Windows下创建.gitgnore文件

    相信使用过git的朋友可能遇到过,直接在windows下创建.gitgnore文件失败.类似截图那样 上网查了一下,有两种方法. 方法1: 此方法较为简单,前提是安装了git bash. 用git b ...

  10. 真正的Java学习从入门到精通

    http://www.it.com.cn/f/edu/059/6/169189.htm 一. 工具篇JDK (Java Development Kit) JDK是整个Java的核心,包括了Java运行 ...