# 爱奇艺2017C/C++笔试练习题

1、求数列的和

Time Limit: 2000/2000 MS (Others/C,C++) Memory Limit: 32768/32768 K (Others/C,C++)
Problem Description:

81 4
2 2

94.7

33.41

#include<iostream>
#include<vector>
#include <cmath>
#include<stdio.h>
using namespace std;
float compute(int n,int m){
float p = n;
float result = p;
for(int i = 0; i < m - 1;++i){
float k = sqrt(p);
p = k;
result += k;
}
return result;
}
int main(){
vector<int> vec;
int m,n;
while(scanf("%d%d",&n,&m) != EOF){
vec.push_back(n);
vec.push_back(m);
}
int len = vec.size();
vector<float>  res;
for(int i = 0; i < len; i = i + 2){
n = vec[i];
m = vec[i + 1];
res.push_back(compute(n,m));
}
for(int j = 0; j < res.size(); ++j){
printf("%.2f\n",res[j]);
}
}
2、求水仙花数

100 120
300 380

no
370 371

#include<iostream>
#include<vector>
#include <cmath>
#include<stdio.h>
using namespace std;
bool compute(int x){
bool flag = false;
int i,j,k,temp,num;
i = x / 100;
temp = x / 10;
j = temp % 10;
k = x % 10;
num = i * i * i + j * j * j + k * k * k;
if(num == x) return true;
else return false;
}
int main(){
vector<int> vec;
int m,n;
while(scanf("%d%d",&n,&m) != EOF){
vec.push_back(n);
vec.push_back(m);
}
int len = vec.size();
int k = 0;
vector<vector<int>>  vec;
for(int i = 0; i < len;i = i + 2){
m = vec[i];
n = vec[i + 1];
for(int j = m; j <= n; ++j){
if(compute(j))
vec[k].push_back(j);
}
++k;
}
for(int i = 0; i < vec.size(); ++i){
for(int j = 0; j < vec[i].size();++j){
cout<<vec[i][j];
}
if(vec[i].size() == 0)
cout<<"no";
cout<<endl;
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：爱奇艺2017C/C++笔试练习题 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)