Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=9
【题解】:
这题卡了一下,卡在负数的情况,负数输出 0
这题主要找到一个个相邻重复的位置,然后加1上去,看是否进位,直到满足条件为止
【code】:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std; void inttostr(int n,char *str)
{
int cnt=;
while(n)
{
str[cnt]=n%+'';
n/=;
cnt++;
}
str[cnt]='\0';
// cout<<str<<endl;
int i;
for(i=;i<cnt/;i++)
{
swap(str[i],str[cnt-i-]);
}
} int CheckRight(char *str)
{
int len = strlen(str);
int i;
for(i=;i<len;i++)
{
if(str[i]==str[i-]&&str[i]!='')
{
return i;
}
}
return -;
} int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int m;
scanf("%d",&m);
if(m<)
{
printf("%d\n",);
continue;
}
if(m<)
{
printf("%d\n",m+);
continue;
}
char str[];
inttostr(m,str);
if(CheckRight(str)==-)
{
m++;
inttostr(m,str);
}
while()
{
int id = CheckRight(str);
if(id==-)
{
break;
}
else
{
int len = strlen(str);
int i,j;
str[id]++;
for(i=id+;i<len;i++)
{
str[i]='';
}
for(i=id;i>=;i--)
{
if(str[i]>'')
{
str[i]='';
if(i>)
str[i-]++;
else
{
for(j=len+;j>;j--)
{
str[j]=str[j-]; }
str[j] = '';
}
}
}
}
}
printf("%s\n",str);
}
return ;
}
Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)的更多相关文章
- Contest2037 - CSU Monthly 2013 Oct (problem F :ZZY and his little friends)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=5 [题解]: 没想通这题暴力可以过.... [code]: #inclu ...
- Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1 [题解]:卡特兰数取模 h(n) = h(n-1)*(4*n-2)/( ...
- Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
[题解]: 最短路径问题,保证距离最短的同时,学妹权值最大,哈哈 [code]: #include<iostream> #include<queue> #include< ...
- Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)
[题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...
- Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)
Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...
- ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)
题目链接 ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...
- 实验12:Problem J: 动物爱好者
#define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...
随机推荐
- poj 1987 树的分治
思路:1741的A1送 1. #include<iostream> #include<cstring> #include<algorithm> #include&l ...
- 【转】APP测试要点
APP测试的时候,建议让开发打好包APK和IPA安装包,测试人员自己安装应用,进行测试.在测试过程中需要注意的测试点如下: 1.安装和卸载 ●应用是否可以在IOS不同系统版本或android不同系统版 ...
- 203. Segment Tree Modify
最后更新 二刷 08-Jan-2017 利用线段树来更改,找到更改的NODE,然后更改那个brach上的所有max值. 首先确定recursion的终止条件 然后通过判断大小来找方向 找到NODE之后 ...
- jquery里的宽度详解
在jQuery中,width()方法用于获得元素宽度:innerWidth()方法用于获得包括内边界(padding)的元素宽度,outerWidth()方法用于获得包括内边界(padding)和边框 ...
- javascript笔记——密码组合规则
//6-16个字符,字母加数字或符号的组合密码[必须全部包含] var filter = /^(?=.*[0-9])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[A-Z]) ...
- Java-IO 输入输出流详解
一.文件的编码 开发时一定要注意项目默认的编码!!!!!!!! 文件操作的时候一定要记得关闭!!!!!!!! ASCII:美国标准 ...
- mybatis like 查询
SELECT * FROM user WHERE name like CONCAT('%',#{name},'%')
- easyui知识累计.递增.
(001) 偶然发现 easyui 1.4.4 版本以下在使用easyloader时的一个bug(声明:只有在使用easyloader加载模块时有此问题) : (只测试过1.4.2, 1.4.3, 1 ...
- 一些常用sqlite语句
1,如果表不存在就新建一个 CComBSTR bstrCreatBat(L”CREATE TABLE IF NOT EXISTS tb_Name (\ rowIdIndex INTEGER PRIM ...
- ZigBee2006,2007,pro各个版本的区别
文章转载自http://home.eeworld.com.cn/my/space-uid-361439-blogid-224722.html