传送门
东方博宜oj答案1000-1050https://blog.csdn.net/like_astar/article/details/128881011?spm=1001.2014.3001.5502东方博宜oj答案1051-1100
https://blog.csdn.net/like_astar/article/details/128984236?spm=1001.2014.3001.5502东方博宜oj答案1101-1150
https://blog.csdn.net/like_astar/article/details/129061470?spm=1001.2014.3001.5502老样子,不说屁话,直接开始
以后一些非常easy的题就不写注释了,当题目稍难一点或者有比较关键的变量的时候会写详细的注释以便大家阅读
1151
桐桐数:一个数若能分解为两个素数的乘积,那么这个数就是桐桐数。虽然我也不知道桐桐是谁但是洛谷上也有桐桐的题
#include <iostream>
#include <cmath>
using namespace std;
bool prime(int n)
{
int prime = 1;
for (int i = 2; i <= sqrt(n); i++)
{
if (n % i == 0)
{
prime = 0;
break;
}
}
if (prime == 1)
{
return true;
}
else
{
return false;
}
}
void tongtong(int n)
{
int judge = 0;
for (int i = 2; i <= sqrt(n); i++)
{
if (prime(i) == true && n % i == 0 && prime(n / i) == true)
{
cout << "It's a Tongtong number.";
judge = 1;
}
}
if (judge == 0)
{
cout << "It's not a Tongtong number.";
}
}
int main()
{
int n;
cin >> n;
tongtong(n);
return 0;
}
1152
排序后输出首末元素就彳亍了
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
sort(p, p + n);
cout << p[n - 1] << " " << p[0];
delete[]p;
return 0;
}
1153
#include <iostream>
using namespace std;
int main()
{
int m;
cin >> m;
int* p = new int[m];
for (int i = 0; i < m; i++)
{
cin >> p[i];
}
for (int i = 1; i <= m - 2; i++)
{
if (p[i] > p[i - 1] && p[i] > p[i + 1])
{
cout << p[i] << endl;
}
}
delete[]p;
return 0;
}
1154
#include <iostream>
using namespace std;
int main()
{
int m;
cin >> m;
int* p = new int[m];
for (int i = 0; i < m; i++)
{
cin >> p[i];
}
int n;
cin >> n;
int judge = 0;//用于判断
for (int i = 0; i < m; i++)
{
if (p[i] == n)
{
cout << i + 1;
judge = 1;//找到了
break;
}
}
if (judge == 0)//没找到
{
cout << -1;
}
delete[]p;
return 0;
}
1155
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;//家里的人数
int* p = new int[n+1];//开辟动态数组
double sum = 0;
for (int i = 1; i < n + 1; i++)
{
cin >> p[i];
sum += p[i];
}
cout << "AVE=";
cout << fixed << setprecision(1) << sum / n << endl;
for (int i = 1; i < n + 1; i++)
{
if (p[i] > sum / n)
{
cout << i << ":" << p[i] << " ";
}
}
delete[]p;
return 0;
}
1156
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
int* q = new int[n];//本来想着如果有异形基因就把数组后面的元素前移覆盖掉,后来觉得太麻烦了不如直接新开一个数组放,反而更好理解
int num = 0;//统计正常基因个数
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
for (int i = 0; i < n; i++)
{
if (p[i] * p[i] % 7 == 1)//异形基因
{
continue;
}
else
{
q[num] = p[i];
num++;
}
}
for (int i = 0; i < num; i++)
{
cout << q[i] << " ";
}
delete[]p;
delete[]q;
return 0;
}
1157
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
int num1 = 0;
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
int num2 = p[0];
for (int i = 0; i < n; i++)
{
if (p[i] < num2)
{
num2 = p[i];
num1 = i;
}
}
int temp = p[0];//交换最小的数和第一个数
p[0] = p[num1];
p[num1] = temp;
cout << num1 + 1 << endl;//最小数的位置
for (int i = 0; i < n; i++)
{
cout << p[i] << " ";
}
delete[]p;
return 0;
}
1158
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
for (int i = 0; i < n; i++)
{
if (p[i] % 2 != 0)
{
cout << p[i] << " ";
}
}
cout << endl;
for (int i = 0; i < n; i++)
{
if (p[i] % 2 == 0)
{
cout << p[i] << " ";
}
}
delete[]p;
return 0;
}
1159
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n + 1];
for (int i = 1; i < n+1; i++)
{
cin >> p[i];
}
int loc;
cin >> loc;
int temp = p[loc];//记录一下要求位置的元素
for (int i = loc; i < n; i++)
{
p[i] = p[i + 1];
}
for (int i = 1; i < n; i++)
{
cout << p[i] << " ";
}
cout << temp;//把要求的元素放在最后
delete[]p;
return 0;
}
1160
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
int sum = 0;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
sum += p[i];
}
cout << fixed << setprecision(2) << 100 + (sum - 100) * 0.9;
delete[]p;
return 0;
}
1161
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
//思路:开辟一个长度为n的数组放数,然后再开辟一个n+1的数组把前一个数组的数以及待添加的数放到一起然后排序就好了
int m;
cin >> m;//待插入的数
int n;
cin >> n;
int* p = new int[n];
int* q = new int[n + 1];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
for (int i = 0; i < n; i++)
{
q[i] = p[i];
}
q[n] = m;
sort(q, q + n + 1);
for (int i = 0; i < n + 1; i++)
{
cout << q[i] << " ";
}
delete[]p;
delete[]q;
return 0;
}
1162
不输出指定元素就好了
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n + 1];
for (int i = 1; i < n + 1; i++)
{
cin >> p[i];
}
int m;
cin >> m;
for (int i = 1; i < n + 1; i++)
{
if (i == m)
{
continue;
}
else
{
cout << p[i] << " ";
}
}
delete[]p;
return 0;
}
1163
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
int max = 0;//记录最大值
int sum = 0;//记录加和的值并与max比较
int loc = 0;//记录位置
for (int i = 0; i < n - 3; i++)
{
sum += p[i] + p[i + 1] + p[i + 2] + p[i + 3];
if (sum > max)
{
max = sum;
loc = i + 1;//因为i从0开始所以在记录位置的时候要+1
}
sum = 0;//记得在一次循环的末尾将sum置为0,不然会一直加
}
if (p[n - 3] + p[n - 2] + p[n - 1] + p[0] > max)//把最后的情况也就是最后三个与第一个的情况单拎出讨论
{
max = p[n - 3] + p[n - 2] + p[n - 1] + p[0];
loc = n - 2;
}
cout << max << endl;
cout << loc;
delete[]p;//记得释放堆区内存
return 0;
}
1164
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
getline(cin, a);
int judge = 0;
int num = 0;
int num2 = 0;
for (int i = 0; i < 26; i++)
{
for (int j = 0; j < a.size() - 1; j++)
{
if (a[j] == 97 + i)//遍历字符串,寻找相应字母的ASCII码
{
num++;
}
}
if (num != 0)//当字母有出现时才输出,否则不输出
{
cout << (char)(97 + i) << ":" << num << " ";
num = 0;
num2++;
if (num2 % 5 == 0)//每输出5个就换行
{
cout << endl;
}
}
}
return 0;
}
1165
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
int* p = new int[N];
double average = 0;
double max = 0;
for (int i = 0; i < N; i++)
{
cin >> p[i];
}
for (int i = 0; i < N - M + 1; i++)
{
for (int j = 0; j < M; j++)
{
average += p[i + j];//这行给了个警告,但是运行没有问题,我也不知道问题出在哪,有没有佬解释一下
}
average /= M;//求平均
if (average > max)
{
max = average;//与max比较,因为max一开始是0所以肯定可以赋值成功
}
average = 0;//记得置0!!
}
cout << fixed << setprecision(2) << max;
delete[]p;
return 0;
}
1166
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
int* q = new int[n];//开两个数组
int sum = 0;
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0;; j++)
{
if (p[i] / (int)pow(10, j) == 0)
{
break;
}
else
{
sum += p[i] / (int)pow(10, j) % 10;//读取每个数位
}
}
q[i] = sum;
sum = 0;
}
sort(q, q + n);//排序
for (int i = 0; i < n; i++)
{
cout << q[i] << " ";
}
delete[]p;
delete[]q;
return 0;
}
1167
很抱歉,我暂时写不出来,有一个点想了挺久都没有想出来要怎么搞,因为只剩这一道题没写了所以我暂时先发出来,等到我会写了我再补充上来。
再次抱歉。
1168
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
sort(p, p + n);
double sum = 0;
for (int i = 1; i < n - 1; i++)
{
sum += p[i];
}
sum /= n-2;
cout << fixed << setprecision(2) << sum;
delete[]p;
return 0;
}
1169
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
return a > b;//重载sort函数,sort函数默认升序输出,这里将其重载为降序
}
int main()
{
int a[10];
for (int i = 0; i < 10; i++)
{
cin >> a[i];
}
sort(a, a + 10, cmp);//sort函数,需要algorithm头文件
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
return 0;
}
1170
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
int max = 0;
for (int i = 0; i < n; i++)
{
cin >> p[i];
if (p[i] > max)
{
max = p[i];
}
}
for (int i = 0; i < n; i++)
{
if (max == p[i])
{
cout << i + 1 << endl;
}
}
delete[]p;
return 0;
}
1171
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
int f_b, f_e, b_b, b_e;//分别为front_begin(前面开始),front_end(前面结束),behind_begin(后面开始),behind_end(后面结束)
cin >> f_b >> f_e >> b_b >> b_e;
int num = f_e - f_b + 1;//要交换的次数,比如3 5的话那么就要交换5-3+1=3次
for (int i = 0; i < num; i++)//锁定头部开始与尾部开始的位置,然后交换后两边各自往右边递增一个,如果看不懂的话拿笔推算一下就彳亍
{
int temp = p[f_b + i - 1];//因为元素的位置比元素的下标要大1,所以这里减掉1
p[f_b + i - 1] = p[b_b + i - 1];
p[b_b + i - 1] = temp;
}
for (int i = 0; i < n; i++)
{
cout << p[i] << " ";
}
delete[]p;
return 0;
}
1172
如果第三大的数是1也许还难一点,它这里所谓的第几大其实就是降序排序后第k个数而已
#include <iostream>
#include <algorithm>
bool cmp(int a, int b)
{
return a > b;
}
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
sort(p, p + n, cmp);
cout << p[k-1];
delete[]p;
return 0;
}
1173
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
int judge = 0;//这个judge在这里起到一个类似开关的作用,当这个数列整体递减的时候赋值为1,递增的时候赋值为2
//目的就是找到递增递减变化的那个点
int num = 0;
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
if (p[0] > p[1])
{
judge = 1;
}
else
{
judge = 2;
}
for (int i = 1; i < n - 1; i++)
{
if (p[i] < p[i + 1] && judge == 1)
{
num++;
judge = 2;
}
else if (p[i] > p[i + 1] && judge == 2)
{
num++;
judge = 1;
}
else
{
continue;
}
}
cout << num + 1;//因为num记录的是间断点的个数,所以子列个数应该在此基础上+1
delete[]p;
return 0;
}
1174
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
int sum1 = 0;
int sum2 = 0;
for (int i = 0; i < n; i++)
{
if (p[i] % 2 == 0)
{
sum2 += p[i];
}
else
{
sum1 += p[i];
}
}
cout << sum1 << endl;
cout << sum2;
delete[]p;
return 0;
}
1175
#include <iostream>
#include <algorithm>
#include <iomanip>
bool cmp(int a, int b)
{
return a > b;
}
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
double sum = 0;
for (int i = 0; i < n; i++)
{
cin >> p[i];
sum += p[i];
}
cout << sum << endl;
sum /= n;
cout << fixed << setprecision(2) << sum << endl;
sort(p, p + n, cmp);
for (int i = 0; i < n; i++)
{
cout << p[i] << " ";
}
delete[]p;
return 0;
}
1176
#include <iostream>
#include <cmath>
using namespace std;
bool prime(int& n)
{
int prime = 1;
for (int i = 2; i <= sqrt(n); i++)
{
if (n % i == 0)
{
prime = 0;
break;
}
}
if (prime == 1)
{
return true;
}
else
{
return false;
}
}
int main()
{
int a[100];
int num1 = 0;
for (int i = 0;; i++)
{
cin >> a[i];
num1++;
if (a[i] == 0)
{
break;
}
}
num1 -= 1;//num1会把0也录入,要去掉,这个记录的是输入数字的个数
int num2 = 0;//统计质数个数
for (int i = 0; i < num1; i++)
{
for (int j = 1; j <= a[i]; j++)
{
if (prime(j) == true)
{
num2++;
}
}
cout << num2 - 1 << endl;//这个prime函数有个弊端,就是会把1当成质数,所以这里要减一
num2 = 0;
}
return 0;
}
1177
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
getline(cin, a);
int b[26] = { 0 };
int num = 0;
for (int i = 0; i < 26; i++)
{
int judge = 0;
for (int j = 0; j < a.size(); j++)
{
if (a[j] == (char)(97+i) && judge == 0)//我们只需要输出有的元素,所以在这里利用judge,如果为0输出字母,为1则不用再输出
{
cout << a[j];
judge = 1;
num++;
}
if (a[j] == (char)(97+i) && judge == 1)
{
num++;
}
}
b[i] = num-1;
num = 0;
}
cout << endl;
for (int i = 0; i < 26; i++)
{
if (b[i] > 0)
{
cout << b[i];
}
}
return 0;
}
1178
非常朴素的做法
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int num0 = 0;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
int num7 = 0;
int num8 = 0;
int num9 = 0;
for (int i = 1; i <= n; i++)
{
int num = i;
while (num != 0)
{
if (num % 10 == 0)
{
num0++;
}
if (num % 10 == 1)
{
num1++;
}
if (num % 10 == 2)
{
num2++;
}
if (num % 10 == 3)
{
num3++;
}
if (num % 10 == 4)
{
num4++;
}
if (num % 10 == 5)
{
num5++;
}
if (num % 10 == 6)
{
num6++;
}
if (num % 10 == 7)
{
num7++;
}
if (num % 10 == 8)
{
num8++;
}
if (num % 10 == 9)
{
num9++;
}
num /= 10;
}
}
cout << num0 << endl;
cout << num1 << endl;
cout << num2 << endl;
cout << num3 << endl;
cout << num4 << endl;
cout << num5 << endl;
cout << num6 << endl;
cout << num7 << endl;
cout << num8 << endl;
cout << num9;
return 0;
}
1179
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
double num1 = 0;//平均数
int num2 = 0;//众数
int num = 0;
int num_2 = 0;
double num3 = 0;//中位数
for (int i = 0; i < n; i++)
{
cin >> p[i];
num1 += p[i];
}
num1 /= n;
cout << fixed << setprecision(2) << num1 << " ";
sort(p, p + n);//排序
for (int i = 0; i < n; i++)//找众数
{
for (int j = 0; j < n; j++)
{
if (p[i] == p[j])
{
num++;
}
}
if (num > num_2)
{
num2 = p[i];
num_2 = num;
num = 0;
}
else
{
num = 0;
}
}
cout << num2 << " ";
if (n % 2 == 0)//找中位数
{
num3 = (p[n / 2] + p[n / 2 - 1]) / 2.0;
cout << fixed << setprecision(1) << num3;
}
if (n % 2 == 1)
{
num3 = p[(n - 1) / 2];
cout << fixed << setprecision(1) << num3;
}
return 0;
}
1180
将找众数(上一题)稍作修改即可
#include <iostream>
using namespace std;
int main()
{
int p[50];
int num = 0;
int num_2 = 0;
for (int i = 0; i < 50; i++)
{
cin >> p[i];
}
for (int i = 0; i < 50; i++)
{
for (int j = 0; j < 50; j++)
{
if (p[i] == p[j])
{
num++;
}
}
if (num > num_2)
{
num_2 = num;
num = 0;
}
else
{
num = 0;
}
}
cout << num_2;
return 0;
}
1181
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
getchar();//用于吸收回车
string a;
int num = 0;
for (int i = 1; i <= n; i++)
{
getline(cin, a);
if (!(a[0] == 65 || a[0] == 66 || a[0] == 67 || a[0] == 68 || a[0] == 69 || a[0] == 70 || a[0] == 71 || a[0] == 82 || a[0] == 83 || a[0] == 84))
{
num++;
}
}
cout << num;
return 0;
}
1182
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
getline(cin, a);
for (int i = 0; i < a.size(); i++)
{
if (a[i] >= 65 && a[i] <= 90)
{
a[i] += 32;
cout << a[i];
}
else if(a[i]>=97&&a[i]<=122)
{
a[i] -= 32;
cout << a[i];
}
else
{
cout << a[i];
}
}
return 0;
}
1183
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
sort(p, p + n);//排序
int num = 0;
int judge = 0;//用于判断
for (int i = 0; i < n; i++)
{
for (int j = i - 1; j >= 0; j--)
{
if (p[i] == p[j])//前面有相等的数字,证明重复了
{
judge = 1;
}
}
if (judge == 0)
{
num++;//重复的数字只有第一个会记
}
judge = 0;//记得重新置0
}
cout << num << endl;
for (int i = 0; i < n; i++)
{
for (int j = i - 1; j >= 0; j--)
{
if (p[i] == p[j])
{
judge = 1;
}
}
if (judge == 0)
{
cout << p[i] << endl;
}
judge = 0;
}
delete[]p;
return 0;
}
1184
后面基本上是二维数组的专项练习(虽然我也有用一维数组),大致的思路其实都是类似的,哪怕难一点稍微花一点时间也是可以想出来的,所以就不写注释了。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
int num = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << setw(3) << num;
num++;
}
cout << endl;
}
return 0;
}
1185
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int num = n * (n - i) + 1;
for (int j = 1; j <= n; j++)
{
cout << setw(3) << num;
num++;
}
cout << endl;
}
return 0;
}
1186
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << setw(3) << i + (j - 1) * n;
}
cout << endl;
}
return 0;
}
1187
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << setw(3) << n * (n - 1) + i - (j - 1) * n;
}
cout << endl;
}
return 0;
}
1188
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << setw(3) << n * (n - i + 1) - (j - 1);
}
cout << endl;
}
return 0;
}
1189
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << setw(3) << n * i - (j - 1);
}
cout << endl;
}
return 0;
}
1190
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == j)
{
a[i][j] = 1;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = 0;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1191
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j ==n+1-i)
{
a[i][j] = 1;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = 0;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1192
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
a[i][j] = i + j - 1;
cout << setw(3) << a[i][j];
}
cout << endl;
}
return 0;
}
1193
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i + j - 1 <= n)
{
a[i][j] = i + j - 1;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = -(i + j) + 2 * n + 1;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1194
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
char a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i + j - 1 <= n)
{
a[i][j] = 64 + i + j - 1;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = 64 + i + j - n - 1;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1195
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == j)
{
a[i][j] = n;
cout << setw(3) << a[i][j];
}
else
{
int num = abs(i - j);//重要,把这个方阵看成斜着的一条一条,然后主对角线等于n,其他根据i+j与2*i(对角线的位置)的差的绝对值来计算
a[i][j] = n - num;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1196
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j <= i)
{
a[i][j] = j;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = i;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1197
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j <= i)
{
a[i][j] = n + 1 - i;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = n + 1 - j;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1198
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (n + 1 - j > n + 1 - i)
{
a[i][j] = n + 1 - j;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = n + 1 - i;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1199
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j < i)
{
a[i][j] = i;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = j;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
1200
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int n;
int a[10][10];
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (n + 1 - j > i)
{
a[i][j] = i;
cout << setw(3) << a[i][j];
}
else
{
a[i][j] = n + 1 - j;
cout << setw(3) << a[i][j];
}
}
cout << endl;
}
return 0;
}
二维数组的这一堆题是一口气做的,差点寄了,最后几道题全靠意念。那到这里1151-1200就结束了,后面的内容等我慢慢出哈,现在开学了课好多555,我会尽快更的。