求最大递增数

输入一串数字,找到其中包含的最大递增数。递增数是指相邻的数位从小到大排列的数字。如: 2895345323,递增数有:289,345,23, 那么最大的递减数为345。
运行时间限制: 无限制
内存限制: 无限制
输入:
输入一串数字,默认这串数字是正确的,即里面不含有字符/空格等情况
输出:
输出最大递增数
样例输入:
123526897215
样例输出:

2689


华为机试题,要注意处理多余的数组空间,发现vs2012有的时候加注释代码报错,不知道什么原因?

#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	char input[100]; 
	int heap[10]={0};
	cout<<"please input your numbers:"<<endl;
	cin>>input;
	char tmp[10];
	int t= 0;
	int h=0;
	for(int i =0;i<strlen(input);i++) {
		tmp[t]=input[i];
		i++;
		while(input[i]>tmp[t]) {
			tmp[++t]=input[i++];
		}
		tmp[t+1]='\0';
		t=0;
		while (tmp[t]!='\0')
		{
			heap[h]+=(tmp[t]-'0')*pow(10,strlen(tmp)-t-1);
			t++;
		}
		memset(tmp,'\0',10);
		t=0;
		h++;
		i--;
	}
	int max =heap[0];
	for (int h = 0; h < sizeof(heap)/sizeof(int)&&heap[h]>0; h++)
	{
		max=heap[h]>max?heap[h]:max;
	}
	cout<<max<<endl;
	system("PAUSE");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值