本次采用C++语言代码解析
#include<bits/stdc++.h> 为万能头---大家将来会了解
另外代码都是AC之后的代码,可以正常通过一般样例
第一题--小黄人yyds 没有什么好说的,注意次数就行了
#include<bits/stdc++.h>
using namespace std;
int main()
{
for(int i=1;i<=100;i++){
cout<<"xiaohuangren yyds\n";
}
}
第二题--输入一个数,判断是不是水仙花数
此题虽然可以判断 数值 sum>99&&sum<1000 但实际上有一些情况是 00#或者 0## 此时sum虽然是三位数字,但并不符合>99&&<1000
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
if(s.length()!=3){
cout<<"输入错误,不是一个三位数";
}
else{
int a=s[0]-'0';
int b=s[1]-'0';
int c=s[2]-'0';
int sum=a*100+b*10+c;
if(a*a*a+b*b*b+c*c*c==sum)cout<<"该数是水仙花数";
else cout<<"该数不是水仙花数";
}
//此题虽然可以判断 数值 sum>99&&sum<1000但实际上有一些情况是 00#或者 0## 此时sum虽然是三位数字,但并不符合>99&&<1000
}
第三题--分解质因数
可以直接暴力求出从2到n/i的质因数(每个合数都是由质因数乘积得到),当然也可以写质数筛,两种都可以。前者比较简单
#include<bits/stdc++.h>
using namespace std;
int main()
{
int l,r;
cin>>l>>r;
for(int i=l;i<=r;i++){
cout<<i<<"=";
int temp=i;
bool ok=false;
for(int k=2;k<=

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



