Divisible by Seven CodeForces - 376C (数论)
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't
contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 106 characters.
Print a number in the decimal notation without leading zeroes — the result of the permutation.
If it is impossible to rearrange the digits of the number a in the required manner, print 0.
1689
1869
18906
18690
//这道题的思路就是(1).如果在没有0的情况下把1689的任意组合放在后四位,而且1689的组合对1,6,8,9都只取一次
//然后把剩下的数放在前面,这些数对7取余只有0~6这几种情况,所以把这些数对7取余之后的余数再与
//1689的任意组合放在一起,看看哪种组合可以对7取余等于0.
//(2).当输入的数中有0的话,计算一共有多少个0,然后再进行1中的过程,不过把0最后输出就行了
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=1010000; char str[maxn],a[maxn];
char xsk[10][5]= {"1869","1968","1689","6198","1698","1986","1896"};//对7取余,余数为0~6的组合情况
int s1,s2,s3,s4;
int main()
{
while(~scanf("%s%*c",str))
{
s1=s2=s3=s4=1;
int t=0,sum1=0,sum2=0;
int len=strlen(str);
for(int i=0; i<len; i++)
if(str[i]=='0')
sum1++;
for(int i=0; i<len; i++)
{
if(str[i]=='0') continue;
if(str[i]=='1'&&s1)
{
s1--;
continue;
}
if(str[i]=='6'&&s2)
{
s2--;
continue;
}
if(str[i]=='8'&&s3)
{
s3--;
continue;
}
if(str[i]=='9'&&s4)
{
s4--;
continue;
}
a[t++]=str[i];
sum2=(sum2*10+str[i]-'0')%7;
}
printf("%s",a);
if(sum2==0)printf("%s",xsk[0]);
if(sum2==1)printf("%s",xsk[3]);
if(sum2==2)printf("%s",xsk[6]);
if(sum2==3)printf("%s",xsk[2]);
if(sum2==4)printf("%s",xsk[5]);
if(sum2==5)printf("%s",xsk[1]);
if(sum2==6)printf("%s",xsk[4]);
for(int i=0; i<sum1; i++)
printf("0");
printf("\n");
}
return 0;
}
Divisible by Seven CodeForces - 376C (数论)的更多相关文章
- CodeForces 300C --数论
A - A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- Codeforces 264B 数论+DP
题目链接:http://codeforces.com/problemset/problem/264/B 代码: #include<cstdio> #include<iostream& ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- CodeForces 1202F(数论,整除分块)
题目 CodeForces 1213G 做法 假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \fr ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- Neko does Maths CodeForces - 1152C 数论欧几里得
Neko does MathsCodeForces - 1152C 题目大意:给两个正整数a,b,找到一个非负整数k使得,a+k和b+k的最小公倍数最小,如果有多个k使得最小公倍数最小的话,输出最小的 ...
- Codeforces 716C[数论][构造]
/* CF傻逼构造题 某人要经过n回合游戏,初始分值是2,等级为1. 每次有两种操作 1.无条件,分值加上自己的等级数. 2.当目前的数字是完全平方数并且该数字开方以后是等级数加1的整数倍,那么可以将 ...
- Codeforces 376C. Socks
C. Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
随机推荐
- c++树,知道前序和中序求后序遍历
经常有面试题就是知道一棵树的前序遍历和中序遍历让你写出后序遍历,这个慢慢画是能画出来的,但是要很快的弄出来还是要懂原理. 首先说一下三种遍历:所谓的前序后序和中序都是遍历时遍历根节点的顺序.子树的话依 ...
- koa源码阅读[0]
koa源码阅读[0] Node.js也是写了两三年的时间了,刚开始学习Node的时候,hello world就是创建一个HttpServer,后来在工作中也是经历过Express.Koa1.x.Koa ...
- three.js_camera相机
https://blog.csdn.net/yangnianbing110/article/details/51275927 文章地址
- [转载]Android中Bitmap和Drawable
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- Android稳定性测试工具Monkey的使用
综述 Monkey是一个命令行工具,它可以运行在我们的模拟器或者设备当中.它可以发送一些伪随机的用户事件流,例如点击.触摸.手势等.我们能够使用Monkey工具来对我们所开发的应用进行压力测试. ...
- 面试中关于Redis的问题看这篇就够了
昨天写了一篇自己搭建redis集群并在自己项目中使用的文章,今天早上看别人写的面经发现redis在面试中还是比较常问的(笔主主Java方向).所以查阅官方文档以及他人造好的轮子,总结了一些redis面 ...
- 高性能优秀的服务框架-dubbo介绍
先来了解一下这些年架构的变化,下面的故事是我编的.... "传统架构":很多年前,刚学完JavaWeb开发的我凭借一人之力就开发了一个网站,网站 所有的功能和应用都集中在一起,方便 ...
- 10 - 函数嵌套-作用域-闭包-LEGB-函数销毁
目录 1 函数嵌套 2 作用域 2.1 global关键字 3 闭包 3.1 nonlocal关键字 4 默认值的作用域 5 变量名解析原则LEGB 6 函数的销毁 1 函数嵌套 一个 ...
- 判断Selenium加载完成
How do you make Selenium 2.0 wait for the page to load? You can also check pageloaded using followin ...
- ../include/squid_md5.h:27:2: error: #error Cannot find OpenSSL MD5 headers【squid安装中】
../include/squid_md5.h:27:2: error: #error Cannot find OpenSSL MD5 headers yum install -y openssl* w ...