其他分享
首页 > 其他分享> > POJ 6187:称体重

POJ 6187:称体重

作者:互联网

“ Ctrl AC!一起 AC!”

题目:忘题戳这

分析:遍历,枚举每个人的体重,但是可以判断大人和小孩,缩小枚举范围。

AC代码:

#include<iostream>
#include<algorithm>
using namespace std;
struct node {
	char name;
	int age;
}a[4];
bool cmp(struct node a, struct node b) {
	return a.age < b.age;//根据年龄排序
}
int main() {
	for (int i = 10; i <= 30; i += 10) {
		for (int j = 10; j <= 30; j += 10) {
			for (int k = j + 10; k <=50; k += 10) {
				for (int e = j + 10; e <= 50; e += 10) {
					if (i + j<k && i + e>k + j&&i!=j&&k!=e&&i+k==j+e) {
						a[0].name = 'z', a[0].age = i;
						a[1].name = 'q', a[1].age = k;
						a[2].name = 's', a[2].age = j;
						a[3].name = 'l', a[3].age = e;
					}
				}
			}
		}
	}
	sort(a, a + 4, cmp);
	for (int i = 0; i < 4; i++) {
		cout << a[i].name << " " << a[i].age << endl;
	}
	return 0;
}

感谢阅读!!!

“ Ctrl AC!一起 AC!”

标签:node,AC,name,int,age,6187,POJ,体重,struct
来源: https://blog.csdn.net/m0_62434776/article/details/122310184