C. Long Beautiful Integer
题目思路还是很直接,首先按要求生成字符串。如果该目标字符串小于原字符串,那么从第k位开始,找到最后一个非9的位置,++,同时如果有9,要考虑进位(一开始没有考虑WA了一次)。
犯了一个错误,就是比较字符串大小时,一开始写的是如果b中有一个小于a,就return false.WA了半天。可以直接用strcmp()。
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
int n,k;
char a[N],b[N];
bool check()
{
for(int i=;i<=n;i++)
{
if(a[i]<b[i])
return true;
if(a[i]>b[i])
return false;
}
return true;
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
scanf("%s",a+);
for(int i=;i<=n;i++)
{
if(i<=k)
b[i]=a[i];
else
b[i]=b[i-k];
}
int p;
if(!check())//strcmp(b+1,a+1)<0
{
p=k;
while(b[p]==''&&p>)//忘记考虑9不能再加1的情况
{
b[p]='';
p--;
}
b[p]++;
for(int i=k+;i<=n;i++)
b[i]=b[i-k];
}
printf("%d\n",n);
for(int i=;i<=n;i++)
printf("%c",b[i]);
printf("\n");
}
return ;
}
C. Long Beautiful Integer的更多相关文章
- Codeforces Round #609 (Div. 2) C. Long Beautiful Integer
链接: https://codeforces.com/contest/1269/problem/C 题意: You are given an integer x of n digits a1,a2,- ...
- C - Long Beautiful Integer codeforces 1269C 构造
题解: 这里的m一定是等于n的,n为数最大为n个9,这n个9一定满足条件,根据题目意思,前k个一定是和原序列前k个相等,因此如果说我们构造出来的大于等于原序列,直接输出就可以了,否则,由于后m-k个一 ...
- Codeforces Round #609 (Div. 2) 题解
Equation Modulo Equality Long Beautiful Integer Domino for Young K Integers Equation \[ Time Limit: ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #609 (Div. 2) A-E简要题解
contest链接:https://codeforces.com/contest/1269 A. Equation 题意:输入一个整数,找到一个a,一个b,使得a-b=n,切a,b都是合数 思路:合数 ...
- hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)
hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- hdu4888 Redraw Beautiful Drawings 最大流+判环
hdu4888 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/6553 ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
随机推荐
- LUA学习笔记(第1-4章)
需要一种简单的脚本语言来代替批处理,它需要足够小巧,同时功能上也应该足够强劲,自然选择了LUA语言. 第一章 Hello World print('Hello World') print(" ...
- ubuntu 14.04 安装wordpress
转者注:若没有Apache + PHP + MySQL环境,请参考我的这篇博客 (1)首先下载wordpress, sudo wget http://wordpress.org/latest.tar. ...
- symfony开发步骤简述
对symfony具体开发也有了一定时间的接触了,下面说一下开发步骤,以备自己以后查看; 1.确定表关系,字段等 2.在相应的模块下的Rescourse下config/Doctrine创建相应的.orm ...
- Ansible: hosts文件拆分为inventory和定义inventory全局变量
前言 随着管理机器的增多,我们在使用Ansible的时候时常会遇到hosts文件过于冗长的问题,极其不便于管理,而将hosts文件拆分为inventory就可解决该问题:另外,hosts中的每个主机条 ...
- ELK-图示nginx中ip的地理位置
一.环境准备: ELK stack 环境一套 geolite数据库文件 二.下载geolite数据库(logstash机器上解压,logstash需调用): geolite官网:https://dev ...
- yum安装logstash 不生效
问题描述 根据logstash的配置方法写了一个配置文件,并放入/etc/logstash/conf.d/目录下,然后我们运行logstash # service logstash start Log ...
- centos6.5下编译安装单实例MySQL5.1
MySQL5.1版本安装3步曲: 1) ./config 指定编译安装参数 2) make 3) make install 查看系统版本号 [root@meinv01 ~]# cat /etc/red ...
- 谈下slot-scope
Vue里有个slot插槽的概念,常用的一般是命名的slot和默认的slot, 这里谈下slot-scope,Vue2.6后改成v-slot slot-scope场景是父组件用子组件的数据,但是样式自己 ...
- codewars--js--Large Factorials--阶乘+大数阶乘
问题描述: In mathematics, the factorial of integer n is written as n!. It is equal to the product of n a ...
- Valiant Hearts: The Great War -- 《勇敢的心》
“友情,爱情,亲情”