C++ 信奥赛 1077:统计满足条件的4位数

1077:统计满足条件的4位数

【题目描述】

给定若干个四位数,求出其中满足以下条件的数的个数:个位数上的数字减去千位数上的数字,再减去百位数上的数字,再减去十位数上的数字的结果大于零。

【输入】

输入为两行,第一行为四位数的个数n,第二行为n个的四位数。(n<=100)

【输出】

输出为一行,包含一个整数,表示满足条件的四位数的个数。

【输入样例】

5
1234 1349 6119 2123 5017

【输出样例】

3
#include <iostream>
using namespace std;

int shuzi(int m){	
	int g,s,b,q;
	q=m/1000;
	b=(m-1000*q)/100;
	s=(m-1000*q-100*b)/10;
	g=m-1000*q-100*b-10*s;
	
	if(g-q-b-s>0){
		return 1; 
	}else{
		return 0;
	}
}

int main() {
	int a;
	cin>>a;
	int manzu=0;
	for(int i=0;i<a;i++){
		int b;
		cin >>b;
		manzu=manzu+shuzi(b);
	}
	cout<<manzu;
	return 1;
	
}

 

posted @ 2023-02-01 17:45  童心少年  阅读(613)  评论(0编辑  收藏  举报