26:统计满足条件的4位数个数

时间:2022-05-07
本文章向大家介绍26:统计满足条件的4位数个数,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

26:统计满足条件的4位数个数

总时间限制: 1000ms 内存限制: 65536kB描述

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

输入输入为两行,第一行为四位数的个数n,第二行为n个的四位数,数与数之间以一个空格分开。(n <= 100)输出输出为一行,包含一个整数,表示满足条件的四位数的个数。样例输入

5
1234 1349 6119 2123 5017

样例输出

3

来源习题(5-7)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     int n;
 9     cin>>n;
10     int tot=0;
11     for(int i=1;i<=n;i++)
12     {
13         int a;
14         cin>>a;
15         if((a%10-((a/1000)%10)-((a/100)%10)-((a/10)%10))>0)
16         tot++;
17     }
18     cout<<tot;
19     return 0;
20 }