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)的更多相关文章

  1. 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 ...

  2. 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)/( ...

  3. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)

    [题解]: 最短路径问题,保证距离最短的同时,学妹权值最大,哈哈 [code]: #include<iostream> #include<queue> #include< ...

  4. Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)

    [题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...

  5. Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)

    Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...

  6. 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, ...

  7. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  8. ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)

    题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...

  9. 实验12:Problem J: 动物爱好者

    #define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...

随机推荐

  1. nmap命令-----基础用法

    系统漏洞扫描之王-nmap   NMap,也就是Network Mapper,是Linux下的网络扫描和嗅探工具包.   其基本功能有三个: (1)是扫描主机端口,嗅探所提供的网络服务 (2)是探测一 ...

  2. Quartz Scheduler(2.2.1) - Working with JobStores

    About Job Stores JobStores are responsible for keeping track of all the work data you give to the sc ...

  3. 软谋在线教育诚招php,java,.net,设计师讲师(可兼职)

    软谋教育专注软件在线教育,依托腾讯课堂.yy课堂授课,在线教授计算机知识,现因业务发展,招聘php,java,.net,设计师讲师各两名,如果您满足以下条件,即可联系我们应聘: 1.相关专业工作经验3 ...

  4. EF4.1之Code first 的几种连接数据库的方式

    通过代码 进行连接和创建数据库的方法主要分为两种: 1.使用用连接字符串(在配置文件里面): 连接字符串: <add name="DbEntities" connection ...

  5. Objective-C中一个方法如何传递多个参数的理解

    原来如此 Objective-C语法中多参数传递方法经常是初学者最容易犯困的地方.我自己也是刚刚悟出来与大家分享. 分析 由于我们已有的语言经验告诉我们定义方法都是: 一个类型匹配一个参数(动态语言甚 ...

  6. select into 、 insert into select 、create table as select复制表

    Insert是T-sql中常用语句,Insert INTO table(field1,field2,...)  values(value1,value2,...)这种形式的在应用程序开发中必不可少.但 ...

  7. Rebind and Rewind in Execution Plans

    http://www.scarydba.com/2011/06/15/rebind-and-rewind-in-execution-plans/ Ever looked at an execution ...

  8. OC 成员变量作用域

    1.  成员变量作用域:    @public :在任何地方都能直接访问对象的成员变量.    @private :只能在当前类的对象方法中直接访问.(@implementation中默认是@priv ...

  9. linux ubuntu vsftp 默认主目录

    vi /etc/passwd 查看/ftp:  后面的目录就是默认目录 这是匿名用户的目录 --------------------------- 使用linux 别的用户,默认在/home/用户名 ...

  10. oracle经典操作sql

    分页: SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A WHERE ROWNUM <= 40)WH ...