C14-循环综合练习
原题链接:49776.蒟蒻队笔记汇总2025-09-14 14:13:50
发布于:江苏
一、循环取位数
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
while (n != 0)
{
cout << n%10 << ' ';
n /= 10; //n = n / 10;
}
// cout << n%10 << endl;
// cout << n/10%10 << endl;
// cout << n/100 << endl;
return 0;
}
二、四叶玫瑰数
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
int a = n%10;
int b = n/10%10;
int c = n/100%10;
int d = n/1000;
if (pow(a,4) + pow(b,4) + pow(c,4) +pow(d,4) == n){
cout << "Yes";
}else {
cout << "No";
}
return 0;
}
三、一尺之棰
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, cnt = 0;
cin >> n;
while (n!=1){
cnt++;
n /= 2;
}
cout << cnt+1;
return 0;
}
四、弹球高度计算
#include <bits/stdc++.h>
using namespace std;
int main(){
double h;
cin >> h;
//循环执行9次
int i=1;
double sum = h; //初始高度
while (i <= 9){
sum += h;
h /= 2;
i++;
}
cout << sum << endl;
cout << h/2 << endl;
return 0;
}
五、年龄计算
格式化输入
#include <bits/stdc++.h>
using namespace std;
int main(){
int y, m, d;
int yy, mm, dd;
// cin >> y >> m >> d;
// cin >> yy >> mm >> dd;
// 格式化输出
scanf("%d-%d-%d", &y, &m, &d);
scanf("%d-%d-%d", &yy, &mm, &dd);
int age = yy - y;
if (mm < m || mm==m && dd < d){
age -= 1;
}
printf("%d", age);
return 0;
}
六、逢7必过
这里空空如也
有帮助,赞一个