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. http://www.cnblogs.com/hoojo/archive/2011/06/08/2075201.html

    http://www.cnblogs.com/hoojo/archive/2011/06/08/2075201.html

  2. zookeeper启动错误 ---- Unable to load database on disk

    zk启动报错 解决办法,进入zkdata目录删除version-2下面的所有文件 参考: https://issues.apache.org/jira/browse/ZOOKEEPER-1546 [h ...

  3. [转载]SecureCRT 绝佳配色方案, 保护你的眼睛

    FROM:http://blog.csdn.net/zklth/article/details/8937905 SecureCRT 绝佳配色方案, 保护你的眼睛   关键词:SecureCRT配色,  ...

  4. jQuery的DOM操作之加入元素和删除元素

    加入元素: .append()--在目标元素之后加入元素. .prepend()--在目标元素之前加入元素. .after()--在目标元素之后换行加入元素: .before()--在目标元素之前加入 ...

  5. vue笔记一

    一.Vue基本知识点 1.声明式渲染 <div id="app">{{ msg }}</div> <script> var app = new ...

  6. mysql开发之---使用游标双层嵌套对总表进行拆分为帖子表和回复表

    注意点: (1)进行拆分的总表表名是不同的.所以创建暂时表,把总表的数据先插入暂时表 (2)为了避免最外层游标轮询数据结束时,抛出 not found 退出程序,不会运行关闭游标等兴许操作,定义con ...

  7. OpenStack二三事(1)

    更新系列不是教材,不说教,不讲道理,仅仅记录. OpenStack在云计算领域大热,没有理由不去了解它. 先说说我对OpenStack的感觉,开源.廉价.麻烦.大家都在用,在了解开发流程后.OpenS ...

  8. OpenStack 网络总结之:openstack中网络的基本概念

    原文:openstack-install-guide-yum-icehouse.pdf/7. Add a networking service/Networking concepts OpenStac ...

  9. dispatch_after中时间的计算

    dispatch_after中用的时间是纳秒,所以需要进行转换:desDelayInSeconds(目标时间,比如2s)* NSEC_PER_SEC double delayInSeconds = 0 ...

  10. php-fpm添加service服务

    原文:http://blog.csdn.net/whatday/article/details/50659992 php-fpm在5.3.2版本以后不支持service php-fpm start等命 ...