一.1233
#include <stdio.h>
int main() {
int k, n;
scanf("%d", &k);
while(k--){
scanf("%d", &n);
char a[60][60];
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
a[i][j] = a[i - 1][j];
printf("%c", a[i][j]);
}
for(int j = i; j <= n; j++){
a[i][j] = 'A' + n - i;
printf("%c", a[i][j]);
}
for(int j = 1; j < n; j++){
a[i][n + j] = a[i][n - j];
printf("%c", a[i][n - j]);
}
printf("\n");
}
for(int i = 1; i < n; i++){
for(int j = 1; j <= 2 * n - 1; j++){
printf("%c", a[n - i][j]);
}
printf("\n");
}
}
return 0;
}
二.1178
#include <stdio.h>
void change(int *a, int *b){
if(*a > *b){
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
return ;
}
int main() {
int n;
scanf("%d", &n);
while(n--){
int x1, y1, x2, y2;
int x3, y3, x4, y4;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
scanf("%d%d%d%d", &x3, &y3, &x4, &y4);
change(&x1, &x2), change(&y1, &y2);
change(&x3, &x4), change(&y3, &y4);
change(&x1, &x3), change(&y1, &y3), change(&x2, &x4), change(&y2, &y4);
if(x3 < x2 && y3 < y2) printf("Yes\n");
else printf("No\n");
}
return 0;
}
三.1187
#include <stdio.h>
#define max_n 1000000007
__int64 c(__int64 x){
if(x < 3) return 0;
return ((x - 2) * (x - 1) * x / 6) % max_n;
}
int main() {
int n;
__int64 x, y, z;
int sum = 0;
while(scanf("%d", &n) != EOF && n != 0){
z = n / 3;
x = z, y = z;
if(n % 3 == 1) x++;
else if(n % 3 == 2) y++, x++;
sum = ((x * y * z ) % max_n + (c(x) + c(y) + c(z)) % max_n) % max_n;
printf("%d\n", sum);
}
return 0;
}
四.1191
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b){
return *(int *)a - *(int *)b;
}
int change(int x){
int arr[4], a = 0, b = 0;
for(int i = 0; i < 4; i++){
arr[i] = x % 10;
x /= 10;
}
qsort(arr, 4, sizeof(int), cmp);
for(int i = 0; i < 4; i++){
a = a * 10 + arr[i];
b = b * 10 + arr[3 - i];
}
return b - a;
}
int main() {
int n;
while(scanf("%d", &n) != EOF && n != 0){
int cnt = 0;
while(n != 6174){
cnt++;
n = change(n);
}
printf("%d\n", cnt);
}
return 0;
}
五.1214
#include <stdio.h>
#include <math.h>
int main() {
int n;
scanf("%d", &n);
while(n--){
int x, y, z;
scanf("%d+%d=%d", &x, &y, &z);
if(x + y == z) {
printf("0\n");
continue;
}
if((z - y) % x == 0){
int i = (int)log10((z - y) / x);
if(x * pow(10, i) + y == z){
printf("%d\n", i);
continue;
}
}
if((z - x) % y == 0){
int j = (int)log10((z - x) / y);
if(y * pow(10, j) + x == z){
printf("-%d\n", j);
continue;
}
}
}
return 0;
}
六.1221
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
while(n--){
unsigned int x, cur = 0, max = 0;
scanf("%d", &x);
while(x){
if(x % 2 == 1) cur++;
else{
cur = 0;
}
if(cur > max) max = cur;
x /= 2;
}
printf("%d\n", max);
}
return 0;
}
七.1127
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
while(n--){
int k, d = 1, x = 0, y = 0;
scanf("%d", &k);
while(k--){
char str[10];
int n;
scanf("%s", str);
if(str[0] == 'F') {
scanf("%d", &n);
if(d == 1) y += n;
else if(d == 2) x += n;
else if(d == 3) y -= n;
else if(d == 4) x -= n;
}
else if(str[0] == 'L'){
if(d == 1) d = 4;
else d--;
}
else if(str[0] == 'R'){
if(d == 4) d = 1;
else d++;
}
else if(str[0] == 'B'){
if(d == 1) d = 3;
else if(d == 2) d = 4;
else if(d == 3) d = 1;
else if(d == 4) d = 2;
}
}
printf("%d %d\n", x, y);
}
return 0;
}
八.1237
#include <stdio.h>
#define max_n 5000000
int prime[max_n + 5];
int prime2[max_n + 5];
int prime3[max_n + 5];
void is_prime(){
for(int i = 2; i <= max_n; i++){
if(!prime2[i]) prime[++prime[0]] = i;
for(int j = 1; j <= prime[0]; j++){
if(i * prime[j] > max_n) break;
prime2[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
}
}
for(int i = 4; i <= max_n; i++){
if(!prime2[i] && !prime2[i - 2]) prime3[i]++;
prime3[i] += prime3[i - 1];
}
return ;
}
int main() {
is_prime();
int n;
scanf("%d", &n);
while(n--){
int x, y;
scanf("%d%d", &x, &y);
printf("%d\n", prime3[y] - prime3[x + 1]);
}
return 0;
}