H面试程序(29):求最大递增数
要求:求最大递增数
如:1231123451
输出12345
#include<stdio.h>
#include<assert.h>
void find(char *s)
{
int maxleng = 0;
int length = 1;
int pos = 0;
int i = 0;
while(s[i] !='\0')
{
if((s[i])<'0'||(s[i]>'9'))
{
assert(0);
}
if((s[i+1]-'0') > (s[i] -'0'))
{
length++;
i++;
continue;
}
if(length > maxleng)
{
maxleng = length;
pos = i -maxleng;
pos++;
length = 1;
i++;
continue;
}
i++;
length = 1;
}
for(int j =0; j < maxleng; j++)
{
printf("%c",s[pos++]);
}
}
int main( )
{
char s[100];
scanf("%s",s);
find(s);
return 0;
}
H面试程序(29):求最大递增数的更多相关文章
- JAVA 基础编程练习题29 【程序 29 求矩阵对角线之和】
29 [程序 29 求矩阵对角线之和] 题目:求一个 3*3 矩阵对角线元素之和 程序分析:利用双重 for 循环控制输入二维数组,再将 a[i][i]累加后输出. package cskaoyan; ...
- JAVA 基础编程练习题25 【程序 25 求回文数】
25 [程序 25 求回文数] 题目:一个 5 位数,判断它是不是回文数.即 12321 是回文数,个位与万位相同,十位与千位相同. package cskaoyan; public class cs ...
- H面试程序(16): 简单选择排序
#include<stdio.h> #include<assert.h> void display(int * a, int n) { assert(a); for(int i ...
- H面试程序(10): 字符串包含问题
题目描述:判断第二个字符串中的元素是否都能在第一个字符串中找到: 注意:和字符串的字串的问题有所区别,如第一个字符串为 abcdefg,第二个字符串为 aaabc,第二个字串还是包含于第一个字符串 ...
- H面试程序(1)编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的 下一秒
编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒. 如输入 2004 年 12 月 31 日 23 时 59 分 59 秒,则输出 2005年 1 月 1 日 0 时 0 分 0 秒. ...
- H面试程序(11): 判断字符串是否包含子串问题
题目描述: 如字符串str1为''abcdef''' 字符串str2为'' bc''; 则字符串str1中含有 ...
- H面试程序(12): 输出字符串中第一个只出现一次的字母
题目描述: 若字符串str为'' sbdddsbfc'',则输出 f; 若字符串str为''aabbccdd'',则输出:字符串str中的字符都出现两次以上 #include <stdio.h& ...
- H面试程序(27):字串转换
//1 字串转换 //问题描述: //将输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:a->b,b->c,…,y->z,z->a: //若输 ...
- H面试程序(15): 冒泡排序法
#include<stdio.h> #include<assert.h> void display(int * a, int n) { for(int i = 0; i < ...
随机推荐
- BaseActivity的定义——作为所有Activity类的父类
public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener { prote ...
- psycopg2关于undefined symbol: lo_truncate64解决方法
今天,在centos6.5下安装psycopg2,利用Python连接PostgreSQL数据库的时候,出现了一个undefined symbol: lo_truncate6的错误: django.c ...
- Digital Roots(hdoj1013)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- bokeh-scala
使用bokeh-scala进行数据可视化 目录 前言 bokeh简介及胡扯 bokeh-scala基本代码 我的封装 总结 一.前言 最近在使用spark集群以及geotrellis框架(相关文章见h ...
- JIT和程序的首次执行
由于C#源代码经过编译器编译生成的是IL代码,而IL是与CPU无关的机器语言.因此当程序运行于特定的CPU时,首先必须将IL转换成本地CPU指令,这正是JIT(Just-In-Time)编译器的任务. ...
- linux下so动态库一些不为人知的秘密(中)
上一篇(linux下so动态库一些不为人知的秘密(上))介绍了linux下so一些依赖问题,本篇将介绍linux的so路径搜索问题. 我们知道linux链接so有两种途径:显示和隐式.所谓显示就是程序 ...
- pushMeBaby,github链接
https://github.com/stefanhafeneger/PushMeBaby
- git备忘录
1.git: patch does not apply git apply --ignore-space-change --ignore-whitespace mychanges.patch 2.Ge ...
- hdu 5199 Gunner(STL之map,水)
Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very ...
- 关于xxx.h file not found 的问题
在引用第三方库的时候,经常会遇到xxx.h file not found的问题. 首先,我们要知道在引用第三方的时候,我们使用的第三方的库的类型. .a静态库 使用方式:#import "x ...