A.数列倒序
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int a[N];
int main()
{
for(int i = 1; i <= 10 ; i ++)
cin >> a[i];
for(int i = 10 ; i >= 1 ; i --)
if(i == 1) cout << a[i]; //最后一个数特判 不加逗号;
else cout << a[i] << ","; //注意输出要加逗号;
return 0;
}
B. A+B进阶练习
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int a[N];
int main()
{
int k;
cin >> k;
while(k --)
{
long long a , b; //害怕数据过大开个long long保险
cin >> a>> b;
long long sum = 0;//害怕数据过大开个long long保险
sum = a + b;
cout << sum << endl;
}
return 0;
}
C.判断质数
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int a[N];
bool prime(int u) //判断是否为质数,如果是为true;否则为false;
{
if(u <= 1) return false;
if(u == 2) return true;
else
{
for(int i = 2 ; i <= sqrt(u) ; i ++)
{
if(u % i == 0) return false;
}
}
return true;
}
int main()
{
int k;
cin >> k;
if(prime(k)) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
D.平均成绩
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N];
int main()
{
for(int i =1 ; i <= 5 ; i ++)
cin >> a[i];
double sum = 0;
for(int i =1 ; i <= 5 ; i ++)
{
sum += a[i];
}
printf("%.0lf" , sum / 5); //只需要保留整数,所以是.0;
return 0;
}
标签:const,int,namespace,long,第一次,using,include,热身赛
From: https://www.cnblogs.com/volapex-lord/p/17923796.html