hiho- 漏写的数字(水)

题目1 : 漏写的数字

时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

小A今年刚上幼儿园,正在学习写100以内的数字。幼儿园的老师留了一项作业,要求小A从某个100以内的数X开始一直写到另一个100以内的数Y(Y - X > 1)。  

不过粗心的小A在作业中漏写了一个整数(好在小A漏写的不是X,并且至少写下了2个整数)。给定小A写下的数字串,你能求小A漏写的数字是多少吗?

输入

一个只包含数字的字符串。注意小A至少写下了两个数。

输出

小A漏写的数字。

样例输入
9111213
样例输出
10
#include<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
const int maxn=1e6+10;
char str[maxn];
int main()
{
 	while(scanf("%s",str)!=EOF)
 	{
 		int len=strlen(str);
 		if(len==2)
 		{
 			if(str[1]-'0'==str[0]-'0'+1)
			 	printf("%d\n",str[1]-'0'+1);
			else printf("%d\n",str[0]-'0'+1);	
		}
		else{
			int i;
			int cnt=0;
			i=str[0]-'0';
			int j=1;
			int ans;
			for(i=i+1;i<100&&j<len;i++)
			{
				//cout<<i<<" ";
				if(i/10==0)
				{
					if(str[j]-'0'!=i)
					{	cnt++;ans=i;
					}
					
					else j++;
				}
				else{
					int sum=(str[j]-'0')*10+(str[j+1]-'0');
					if(sum!=i)
					{
						cnt++;
						ans=i;
					}
					else j+=2;
				}
			}
			if(cnt==1) {
			printf("%d\n",ans);
			continue;
			}
			else{
				j=2;
				i=(str[0]-'0')*10+(str[1]-'0');
				for(i=i+1;i<100&&j<len;i++)
				{
					int sum=(str[j]-'0')*10+(str[j+1]-'0');
					if(sum!=i)
					{
						cnt++;
						ans=i;
					}
					else j+=2;
				}
				printf("%d\n",ans);
			}
		}
	 }
	return 0;
 } 



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值