1.图像相似度
2.错误探测
3.杨辉三角形
4.扫雷游戏
5.矩阵乘法
6.年龄排序
7.离散化基础
#include
using namespace std;
int a[200][200], b[200][200];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> b[i][j];
}
}
int k = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == b[i][j])
k++;
cout << fixed << setprecision(2) << 100.0 * k / (m * n) << endl;
return 0;
}
#include
using namespace std;
int m[200][200], a[200], b[200];
//a[200]为列上1的个数的计数器,b[200]为行上1的个数的计数器
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> m[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i] += m[i][j], b[j] += m[i][j];
//a[i]求行总和,b[j]求列总和
int aa = 0, bb = 0, k, p; //aa为列上奇数的个数,bb为行上奇数的个数
for (int i = 0; i < n; i++) {
if (a[i] % 2)
aa++, k = i; //k 用来标记有问题的一行
if (b[i] % 2)
bb++, p = i; //p用来标记有问题的一列
}
if (aa == 0 && bb == 0)
cout << "OK";
else if (aa == 1 && bb == 1)
cout << k + 1 << " " << p + 1; //只有某个数出问题时才能修改
else
cout << "Corrupt";
return 0;
}
#include
using namespace std;
int a[40][40];
int main() {
int n;
cin >> n;
a[1][1] = 1;//(1,1)初始化为1;(1,0),(1,2)为0
for (int i = 2; i <= n; i++)
for (int j = 1; j <= i; j++)
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cout << a[i][j];
if (j != i)
cout << " ";
}
cout << endl;
}
return 0;
}
#include
using namespace std;
char c[200][200];
int n, m;
int d[8][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
//坐标:右,左,上,下,右上,左上,右下,左下
bool check(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
//检查坐标有无越界
int Count(int i, int j ) {
int cnt = 0;
for (int k = 0; k < 8; k++) {
int x = i + d[k][0];
int y = j + d[k][1];
if (check(x, y) && c[x][y] == '*')
cnt++;
}
return cnt;
}
//计数周围的雷数
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cin >> c[i][j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (c[i][j] == '*')
cout << '*';
else
cout << Count(i, j);
}
cout << endl;
}
return 0;
}
#include
using namespace std;
int a[2000][2000], b[2000][2000];
int main() {
int n, m, k, sum = 0;
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
for (int i = 0; i < m; i++)
for (int j = 0; j < k; j++)
cin >> b[i][j];
for (int i = 0; i < n; i++) {
int c = 0;
for (int h = 0; h < k; h++) {
sum = 0;
for (int j = 0; j < m; j++)
sum += a[i][j] * b[j][h];
if (c)
cout << " ";
cout << sum;
c = 1;
}
cout << endl;
}
return 0;
}
#include
using namespace std;
struct stu{
string name;
string sex;
int year;
int month;
};
stu a[200];
bool cmp(stu b,stu c){
if(b.year>c.year)return 1;
else if(b.year==c.year&&b.month>c.month)return 1;
else return 0;
}
int main(){
int n;
cin>>n;
for(int i=0;i>a[i].name>>a[i].sex>>a[i].year>>a[i].month;
}
sort(a,a+n,cmp);
for(int i=0;i
#include
using namespace std;
int a[20000], b[20000], c[20000];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
c[a[i]] = i;
}
for (int i = 1; i <= n; i++){
if(c)cout<<" ";
cout << c[b[i]];
c=1;
}
return 0;
}