算法基础上机实验——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;
}
本文来自博客园,作者:逆袭怪,转载请注明原文链接:https://www.cnblogs.com/fghjktgbijn/p/17421511.html