一.1255
#include <stdio.h>
#include <math.h>
void swap(int *a, int *b){
if(*a > *b){
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
return ;
}
int main() {
int k;
scanf("%d", &k);
while(k--){
int a, b;
scanf("%d%d", &a, &b);
swap(&a, &b);
int x = (int)sqrt(b * b - a * a);
int y = (int)sqrt(b * b + a * a);
if(x * x + a * a == b * b && x != 0) printf("%d\n", x);
else if(y * y == a * a + b * b) printf("%d\n", y);
else printf("None\n");
}
return 0;
}
二.1256
#include <stdio.h>
int min(int a, int b){
return a > b ? b : a;
}
int main() {
int n;
scanf("%d", &n);
while(n--){
char str[1005];
scanf("%s", str);
int x = 0, y = 0, z = 0;
for(int i = 0; str[i]; i++){
if(str[i] == 'X') x++;
else if(str[i] == 'T') y++;
else if(str[i] == 'U') z++;
}
printf("%d\n", min(x, min(y, z)));
}
return 0;
}
三.1268
#include <stdio.h>
#define max_n 100
int main() {
int k;
scanf("%d", &k);
while(k--){
int m, n, cnt = 0;
scanf("%d%d", &m, &n);
int a[max_n + 5][max_n + 5];
int b[max_n + 5][max_n + 5] = {0};//行最大
int c[max_n + 5][max_n + 5] = {0};//列最小
int e[max_n + 5][max_n + 5] = {0};//行最小
int f[max_n + 5][max_n + 5] = {0};//列最大
int d[max_n * max_n][3] = {0};
for(int i = 0; i < m; i++){
int min = 2000, max = 0;
for(int j = 0; j < n; j++){
scanf("%d", &a[i][j]);
if(a[i][j] > max) max = a[i][j];
if(a[i][j] < min) min = a[i][j];
}
for(int j = 0; j < n; j++){
if(a[i][j] == max) b[i][j] = 1;
if(a[i][j] == min) e[i][j] = 1;
}
}
for(int j = 0; j < n; j++){
int min = 2000, max = 0;
for(int i = 0; i < m; i++){
if(a[i][j] > max) max = a[i][j];
if(a[i][j] < min) min = a[i][j];
}
for(int i = 0; i < m; i++){
if(a[i][j] == max) f[i][j] = 1;
if(a[i][j] == min) c[i][j] = 1;
}
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if((b[i][j] && c[i][j]) || (e[i][j] && f[i][j])){
d[cnt][0] = a[i][j];
d[cnt][1] = i;
d[cnt][2] = j;
cnt++;
}
}
}
if(cnt == 0) printf("None\n");
else {
printf("%d\n", cnt);
for(int i = 0; i < cnt; i++) printf("%d %d %d\n", d[i][1], d[i][2], d[i][0]);
}
}
return 0;
}
四.1271
#include <stdio.h>
#define max_n 100
int main() {
int t;
scanf("%d", &t);
while(t--){
int m, n, k;
int arr1[max_n + 5] = {0};
int arr2[max_n + 5] = {0};
scanf("%d%d%d", &m, &n, &k);
while(k--){
int x, y;
scanf("%d%d", &x, &y);
arr1[x] = 1;
arr2[y] = 1;
}
int cnt1 = 0, cnt2 = 0;
for(int i = 1; i <= m; i++) if(!arr1[i]) cnt1++;
for(int j = 1; j <= n; j++) if(!arr2[j]) cnt2++;
printf("%d\n", cnt1 * n + cnt2 * m - cnt1 * cnt2);
}
return 0;
}
五.1258
#include <stdio.h>
int arr[10][10];
void init(int n){
int cnt = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
arr[i][j] = cnt;
cnt++;
}
}
return ;
}
void left(int x, int y, int n){
while(y--){
int a = arr[x - 1][0];
for(int i = 1; i < n; i++){
arr[x - 1][i - 1] = arr[x - 1][i];
}
arr[x - 1][n - 1] = a;
}
return ;
}
void up(int x, int y, int n){
while(y--){
int a = arr[0][x - 1];
for(int i = 1; i < n; i++){
arr[i - 1][x - 1] = arr[i][x - 1];
}
arr[n - 1][x - 1] = a;
}
return ;
}
void change(char a, int x, int y, int n){
if(a == 'L') left(x, y, n);
if(a == 'R') left(x, n - y, n);
if(a == 'U') up(x, y, n);
if(a == 'D') up(x, n - y, n);
return ;
}
int main() {
int k;
scanf("%d", &k);
while(k--){
int n, m;
scanf("%d%d", &n, &m);
init(n);
while(m--){
char a;
int x, y;
scanf(" %c %d %d", &a, &x, &y); //输入字符时会读取到换行符,用空格跳过任何空白字符
change(a, x, y, n);
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i != 0 || j != 0) printf(" ");
printf("%d", arr[i][j]);
}
}
printf("\n");
}
return 0;
}
六.1253
#include <stdio.h>
#define max_n 1000
int main() {
int n;
while(scanf("%d", &n) != EOF){
int arr[max_n + 5] = {0};
int arr2[max_n + 5] = {0};
for(int i = 1; i <= n; i++){
scanf("%d", &arr[i]);
}
int cnt = 0, num = 0;
while(cnt != n){
for(int i = 1; i <= n; i++){
if(cnt >= arr[i] && !arr2[i]){
arr2[i] = 1;
cnt++;
}
}
if(cnt == n) break;
num++;
for(int i = n; i > 0; i--){
if(cnt >= arr[i] && !arr2[i]){
arr2[i] = 1;
cnt++;
}
}
if(cnt == n) break;
num++;
}
printf("%d\n", num);
}
return 0;
}
七.1248
#include <stdio.h>
int change(int *p){
int x = 0;
if(p[0] == p[1] && p[1] == p[2]) x = p[0] * 100;
else if(p[0] == p[1] && p[0] != p[2]) x = p[0] * 10 + p[2];
else if(p[0] == p[2] && p[1] != p[2]) x = p[0] * 10 + p[1];
else if(p[1] == p[2] && p[0] != p[2]) x = p[1] * 10 + p[0];
else {
for(int i = 0; i < 3; i++){
if(p[i] == 7) p[i] = 1;
x += p[i];
}
}
return x;
}
int main() {
int k;
scanf("%d", &k);
while(k--){
int a[3], b[3];
int x, y;
for(int i = 0; i < 3; i++){
scanf("%d", &a[i]);
if(a[i] == 1) a[i] = 7;
}
for(int i = 0; i < 3; i++){
scanf("%d", &b[i]);
if(b[i] == 1) b[i] = 7;
}
x = change(a), y = change(b);
if(x > y) printf("Alice\n");
else if(x < y) printf("Bob\n");
else printf("Draw\n");
}
return 0;
}
八.1247
#include <stdio.h>
int arr[1005][3005];
int carry;
int main() {
arr[0][1] = 1;
arr[1][1] = 1;
for(int i = 2; i <= 1000; i++){
for(int j = 1; j < 3000; j++){
arr[i][j] = arr[i - 1][j] * i + carry;
carry = arr[i][j] / 10;
arr[i][j] %= 10;
}
}
int t;
scanf("%d", &t);
while(t--){
int n, m;
scanf("%d%d", &n, &m);
printf("%d\n", arr[n][m]);
}
return 0;
}