计蒜客--U型数字

思路:暴力即可,对每一个数量级的数字枚举每一位,判断是否满足U形数字.

最初思路:转换为数字数组,这样判断很难受.

#include<iostream>
#include<cstring>
#include<cstdio> 
#include<algorithm>
#include<stack>
using namespace std;
bool check(int x){
	if(x<1000){
		int a=x%10;
		int b=(x/10)%10;
		int c=(x/100);
		if(a>b&&c>b)	return true;
		else return false;
	}else 	if(x<10000){
		int a=x%10;
		int b=(x/10)%10;
		int c=(x/100)%10;
		int d=(x/1000);
		if(a>b&&d>c&&b!=c)	return true;
		else return false;
	}else if(x<100000){
		int a=x%10;
		int b=(x/10)%10;
		int c=(x/100)%10;
		int d=(x/1000)%10;
		int e=(x/10000);
		if(a>b&&b<c&&c<d&&d<e) return true;
		else if(a>b&&b>c&&c<d&&d<e) return true;
		else if(a>b&&b>c&&c>d&&d<e) return true;
		else return false;
	}
}
int main(){
	int ans=0;
	for(int i=101;i<100000;i++)
		if(check(i)){
			ans++;
		}
	cout<<ans<<endl;
} 
发布了226 篇原创文章 · 获赞 90 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/queque_heiya/article/details/105592793
今日推荐