intjudge(int x, int y){ int n = 0; if(arr[x][y] == '*') { return-1; }
for (int i = x - 1; i <= x + 1; i++) for (int j = y - 1; j <= y + 1; j++) { if (arr[i][j] == '*') { n++; } }
return n; }
intmain(){ int n, m, res; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> arr[i][j]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if((res = judge(i, j)) != -1) cout << res ; else cout << "*"; } cout << endl; } return0; }
vector<int> C; int t = 0; if (A.size() < B.size()) returnadd(B, A); for (int i = 0; i < A.size() || i < B.size(); i++) { // t + = A[i]; if (i < A.size()) t += A[i]; if (i < B.size()) t += B[i]; C.push_back(t % 10); t /= 10; //去进位 } if (t) C.push_back(1); //有无进位判断 reverse(C.begin(), C.end()); return C; }
intmain(){ int tmp; string a, b;
cin >> a >> b; for (int i = a.size() - 1; i >= 0; i--) //逆序存放进数组 A.push_back(a[i] - '0'); for (int i = b.size() - 1; i >= 0; i--) B.push_back(b[i] - '0'); vector<int> res = add(A, B);
intmain(){ string a, b; vector<int> A, B; cin >> a >> b; for (int i = 0; i < a.size(); i++) A.push_back(a[i] - '0'); for (int i = 0; i < b.size(); i++) B.push_back(b[i] - '0'); vector<int> res = mul(A, B);
vector<int> res; int tmp = 0; for (int i = 0; i < A.size() || i < B.size(); i++) { if (i < A.size()) tmp += A[i]; if (i < B.size()) tmp += B[i]; res.push_back(tmp % 10); tmp /= 10; } if (tmp) res.push_back(tmp); return res; }
vector<int> mul(vector<int> A, int b) { vector<int> C; int t = 0; for (int i = 0; i < A.size() || t; i ++ ) { if (i < A.size()) t += A[i] * b; C.push_back(t % 10); t /= 10; } // while (C.size() > 1 && C.back() == 0) C.pop_back();
return C; }
signedmain(){ int x;
cin >> x;
vector<int> res2 = {1}; //阶乘 vector<int> res4 = {0}; //阶乘和 for (int i = 1; i <= x; i++) { vector<int> current = {i}; res2 = mul(res2, i); res4 = add(res2, res4); }
// void transpose(int x, int y, int n){ // for(int i = x - n; i <= x + n; i ++) // { // for(int j = y - n; j <= y + n; j++) // if (i < j) { //若无此判断等于没交换 // swap(matrix[i][j], matrix[j][i]); // } // } // } 由于x和y并不是对称的,这个交换在x,y不同时会出现错误, //如(20,2)与(2,20)交换,尽管要转置的矩阵大小只有3
voidtranspose(int x, int y, int n){ for (int i = 0; i <= n * 2; i++) { for (int j = i + 1; j <= n * 2; j++) { //确保不会重复交换 swap(matrix[x - n + i][y - n + j], matrix[x - n + j][y - n + i]); } } }
voidrotateClockwise(int x, int y, int n){ transpose(x, y, n); for (int i = x - n; i <= x + n; i++) { reverse(matrix[i].begin() + (y - n), matrix[i].begin() + (y + n + 1)); //reverse不包括last所指的元素 } }
voidrotateCounterwise(int x, int y, int n){ transpose(x, y, n); for (int j = y - n; j <= y + n; j++) { for (int i = x - n, k = x + n; i < k; i++, k--) { //双指针 swap(matrix[i][j], matrix[k][j]); } } }
voidinit(int n){ matrix.resize(n + 1, vector<int>(n + 1, 0)); //预留并初始化为0 int tmp = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) matrix[i][j] = tmp++; }
voiddisplay(int n){ for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cout << matrix[i][j] << " "; } cout << endl; } } intmain(){ int n, m; cin >> n >> m; init(n); int x, y, r, z; for (int i = 0; i < m; i++) { cin >> x >> y >> r >> z; //cout << x << y << r << z << endl; if (z == 0) { rotateClockwise(x, y, r); } elseif(z == 1){ rotateCounterwise(x, y, r); } }