算法基础上机实验——2023.5.21

1.

#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int a[110], n, k = 0, count = 0;
    cin >> n;
    while (n != -9999)
    {
        a[k ++] = n;
        cin >> n;
        count ++;
    }
    for (int i = count - 1; i > 0; i --)
    {
        cout << a[i] << ' ';
    }
    cout << a[0] << endl;
	 
    return 0;
}

2.

#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int n;
	cin >> n;
	n = n * 100;
	int cock, hen, chicken;
	int count = 0;
	for (cock = 0; cock <= n; cock ++) {    /* !<外层循环控制公鸡数量取值范围0~n */
		for (hen = 0; hen <= n; hen ++) {   /* !<内层循环控制母鸡数量取值范围0~n */
			for (chicken = 0; chicken <= n; chicken ++) {  
                /* !<内层循环控制小鸡数量取值访问0-n */
				if (5 * cock + 2 * hen + chicken == n) 
				{
                    count ++;	
				}
			}
		}
	}
	cout << count << endl;
	
	return 0; 
}
posted on 2023-05-22 19:20  逆袭怪  阅读(12)  评论(0编辑  收藏  举报