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 ...
随机推荐
- HTML5와 CSS3 적용기
HTML5의 DTD 선언 <!DOCTYPE html> HTML5의 인코딩 선언 <meta charset="utf-8"> 그리고나서는 새로 ...
- Commons Math - Primes
org.apache.commons.math3.primes.Primes 是关于质数操作的工具类. 1. public static boolean isPrime(int n) 判断 n 是否为 ...
- Lombok(1.14.8) - @Log
@Log @Logs,生成一个日志对象. package com.huey.lombok; import lombok.extern.java.Log; @Log public class LogEx ...
- JavaScript学习笔记(10)——JavaScript语法之操作DOM
1.页面输出用document.write()方法,但是不可以在window.onload中用,否则整个html页面将被覆盖. 2.通过javascript获取对象后,改变对象中的html内容:doc ...
- LINQ(隐式表达式、lambda 表达式)
.NET 中一项突破性的创新是 LINQ(Language Integrated Query,语言集成查询),这组语言扩展让你能够不必离开舒适的 C# 语言执行查询. LINQ 定义了用于构建查询表达 ...
- C# 3.0 特性之扩展方法
今天,我们来聊一聊C#的扩展方法. C# 3.0中为我们提供了一个新的特性—扩展方法.什么是扩展方法呢?我们看一下MSDN的注解: 扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型.重新 ...
- c#基础学习笔记-----------委托事件
这里有一个比较简单的委托实例应用(跨窗体操作控件) http://blog.csdn.net/bdstjk/article/details/7004035 还有一个比较详细的介绍并深入理解委托事件的讲 ...
- HDU1857题解(逆向思维trie)
题目link:http://acm.hdu.edu.cn/showproblem.php?pid=1857 先简述一下题目: 有一个RXC的字母矩形,R,C在500内,要匹配m个单词,m在100000 ...
- 最常用的MySQL命令语句
e良师益友网导读:MySQL数据库是应用最广的数据库之一,在MySQL数据库中有各种各样的命令调用语句,在平常工作中非常实用的命令,对于初学者来说,掌握文中的MySQL命令语句,是非常实用的,下面我们 ...
- MySQL忘记密码后重置密码(Mac )
安装好MySQL以后,系统给了个默认的的密码,然后说如果忘记了默认的密码......我复制了默认密码就走过了这一步,这一步就是我漫长旅程的开始.他给的密码太复杂了,当然我得换一个,而且我还要假装我不记 ...