一.1282
#include <stdio.h>
__int64 gcd(__int64 a, __int64 b){
if(b == 0) return a;
return gcd(b, a % b);
}
int main() {
int k;
scanf("%d", &k);
while(k--){
__int64 a, b, m, s;
scanf("%I64d %I64d", &a, &b);
m = a, s = 1;
for(int i = a + 1; i <= b; i++){
s = s * i + m;
m *= i;
__int64 y = gcd(m ,s);
s /= y, m /= y;
}
printf("%I64d/%I64d\n", s, m);
}
return 0;
}
二.1293
#include <stdio.h>
int main() {
int k;
scanf("%d", &k);
while(k--){
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++){
for(int j = 1; j < n - i; j++) printf(" ");
for(int j = 0; j <= i; j++) printf("%c", 'A' + n - 1 - j);
for(int j = 0; j < i; j++) printf("%c", 'A' + n - i + j);
printf("\n");
}
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++) printf(" ");
for(int j = 0; j < n - i; j++) printf("%c", 'A' + n - 1 - j);
for(int j = 1; j < n - i; j++) printf("%c", 'A' + i + j);
printf("\n");
}
}
return 0;
}
三.1272
#include <stdio.h>
#include <math.h>
int main() {
char str[205];
while(scanf("%s", str) != EOF){
int u = 0, d = 0, l = 0, r = 0;
for(int i = 0; str[i]; i++){
if(str[i] == 'U') u++;
else if(str[i] == 'D') d++;
else if(str[i] == 'L') l++;
else if(str[i] == 'R') r++;
}
if(u * d * l * r) printf("No\n");
else{
u = abs(u - d), d = 0;
l = abs(l - r), r = 0;
if(u == l && u * l) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
//这种做法是wa的,但是在例如LR的情况下,替换指令一定回不到原点,而题目测试的可以
四.1273
#include <stdio.h>
#include <stdlib.h>
#define max_n 100000
int cmp(const void *a, const void *b){
return *(int *)a - *(int *)b;
}
int main() {
int k;
scanf("%d", &k);
while(k--){
int n, a[max_n + 5] = {0}, cnt = 0, b[4], flag = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
qsort(a, n, sizeof(int), cmp);
for(int i = 1; i < n; i++){
if(a[i] == a[i - 1]) continue;
b[cnt++] = a[i - 1];
if(cnt == 4){
flag = 1;
break;
}
}
if(flag) printf("No\n");
else {
b[cnt] = a[n - 1];
if(cnt < 3 || b[1] - b[0] == b[3] - b[2]) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
五.1280
#include <stdio.h>
#define p 1000000007
#define max_n 1000
int main() {
char s[max_n + 5];
while(scanf("%s", s) != EOF){
long long sum = 1;
for(int i = 0; s[i]; i++) sum = (sum * 26 + s[i] - 'a') % p;
printf("%lld\n", sum);
}
return 0;
}
六.1292
#include <stdio.h>
#include <string.h>
#define max_n 1000
int main() {
int k;
scanf("%d", &k);
while(k--){
char s[max_n + 5];
scanf("%s", s);
int la = strlen(s);
int n = la / 2, flag = 0, i;
for(i = n; i > 0; i--){
for(int j = 0; j <= la - 2 * i; j++){
for(int k = j; k < i + j; k++){
if(k == i + j - 1 && s[k] == s[k + i]) flag = 1;
if(s[k] != s[k + i]) break;
}
if(flag) break;
}
if(flag) break;
}
//printf("%d\n", i);
if(flag) printf("%d\n", i * 2);
else printf("0\n");
}
return 0;
}
七.1279
#include <stdio.h>
#define max_n 1000000
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 = 2; i <= max_n; i++){
prime3[i] = prime3[i - 1];
for(int j = 1; prime[j] * prime[j] < i; j++){
if(i % prime[j] == 0 && !prime2[i / prime[j]]){
prime3[i] += 1;
break;
}
}
}
return ;
}
int main() {
is_prime();
int k;
scanf("%d", &k);
while(k--){
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", prime3[b] - prime3[a - 1]);
}
return 0;
}
八.1275
#include <stdio.h>
int K,N,T,S,E;
int cnt,num;
int record[50][4];
char Day[5], week[7][5] = {"1","Mon","Tue","Wen","Thur","Fri"};
void solve(int Time[][15],int s,int t)
{
num = 0; // 记录连续空闲的课长
for (int k = t; k < t+T; k ++) // 检查每个T时段内,是否都是空闲的
if (Time[s][k] == 0) // 该时段没有上课,num ++
num ++;
if (num == T) // 连续空闲时长 = 考试时长
{ // 保存进 记录数组
record[cnt][0] = s;
record[cnt][1] = t;
record[cnt][2] = t+T-1;
cnt ++;
}
}
int main()
{
scanf("%d",&K);
while ( K --)
{
cnt = 0;
scanf("%d %d",&N,&T);
int classTime[7][15] = {0}; // 用二维数组记录 每天有哪些课上课
for (int i = 1; i <= N; i ++)
{
scanf("%s %d %d",Day,&S,&E);
if (Day[0] == 'M') // 把上课的时段标记为1
for (int j = S; j <= E; j ++) classTime[1][j] = 1;
if (Day[0] == 'T' && Day[1] == 'u')
for (int j = S; j <= E; j ++) classTime[2][j] = 1;
if (Day[0] == 'W')
for (int j = S; j <= E; j ++) classTime[3][j] = 1;
if (Day[0] == 'T' && Day[1] == 'h')
for (int j = S; j <= E; j ++) classTime[4][j] = 1;
if (Day[0] == 'F')
for (int j = S; j <= E; j ++) classTime[5][j] = 1;
}
for (int i = 1; i <= 5; i ++) // 开始检查周一到周五的空闲时间
{
for (int j = 1; j <= 5-T; j ++) // 上午
solve(classTime,i,j);
for (int j = 5; j <= 9-T; j ++) // 下午
solve(classTime,i,j);
for (int j = 9; j <= 12-T; j ++) // 晚上
solve(classTime,i,j);
}
printf("%d\n",cnt); // 输出
for (int i = 0; i < cnt; i ++)
printf("%s %d %d\n",week[record[i][0]],record[i][1],record[i][2]);
}
}