C++菜鸡选手临阵磨枪的自我记录
basic-1 基础练习 闰年判断
#include<iostream>
using namespace std;
int main()
{
int y;
//cout << "请输入年份: " << endl;
cin >> y;
if (((y % 4 == 0) && (y % 100 != 0))||(y%400==0))
{
cout << "yes" << endl;
}
else
{
cout << "no" << endl;
}
system("pause");
return 0;
}
basic-2 基础练习 01字串
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d, e;
for (a = 0; a < 2; ++a) {
for (b = 0; b < 2; ++b) {
for (c = 0; c < 2; ++c) {
for (d = 0; d < 2; ++d) {
for (e = 0; e < 2; ++e) {
cout << a << b << c << d << e << endl;
}
}
}
}
}
system("pause");
return 0;
}
basic-3 基础练习 字母图形
#include<iostream>
using namespace std;
int main()
{
char a[26][26];
int n, m;
cin >> n >> m;
for (int j = 0; j < m; j++)
{
a[0][j] = 'A' + j;
}
for (int i = 1; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i <= j)
{
a[i][j] = a[i - 1][j] - 1;
}
else if (i > j)
{
a[i][j] = a[i - 1][j] + 1;
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << a[i][j];
}
cout << endl;
}
system("pause");
return 0;
}
basic-4 基础练习 数列特征
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
int MAX = 0;
int MIN = 0;
int sum = 0;
cin >> n;
int arr[10001];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
sort(arr, arr + n);
MAX = arr[n-1];
MIN = arr[0];
for (int i = 0; i < n; i++)
{
sum = sum + arr[i];
}
cout << MAX << endl;
cout << MIN << endl;
cout << sum << endl;
system("pause");
return 0;
}
basic-5 基础练习 查找整数
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, a;
cin >> n;
int arr[1001];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
cin >> a;
int flag = 0;
int num;
for (int i = 0; i < n; i++)
{
if (arr[i] == a)
{
flag = 1;
num = i+1;
break;
}
}
if (flag == 1)
{
cout << num << endl;
}
else
{
cout << "-1" << endl;
}
system("pause");
return 0;
}