其他题解收录都在这了👇👇👇
目录
1036、跟奥巴马一起编程(分数 15)
题目描述:
代码实现:
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int N = in.nextInt();
String c = in.next();
for(int i = 0;i < N;i ++){
System.out.print(c);
}
System.out.println();
int col = (int) Math.round(N / 2.0) - 2;
for(int j = 0;j < col;j ++){
for(int count = 0;count < N;count ++){
if(count == 0 || count == N - 1)
System.out.print(c);
else System.out.print(" ");
}
System.out.println();
}
for(int i = 0;i < N;i ++){
System.out.print(c);
}
System.out.println();
}
}
运行结果:
1037、在霍格沃茨找零钱(分数 20)
题目描述:
代码实现:
import java.util.*;
public class Main{
public static void swap(String[] a, String[] b){
for(int i = 0;i < a.length;i ++){
String temp = a[i];
a[i] = b[i];
b[i] = temp;
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String[] info = in.nextLine().split(" ");
String[] P = info[0].split("\\.");
String[] A = info[1].split("\\.");
boolean flag = false;
//把A当作大的那个,负号输出时再看情况
if(Long.parseLong(P[0]) * 17 * 29 + Integer.parseInt(P[1]) * 17 + Integer.parseInt(P[2])
> Long.parseLong(A[0]) * 17 * 29 + Integer.parseInt(A[1]) * 17 + Integer.parseInt(A[2])){
swap(P,A);
flag = true;
}
long galleonP = Long.parseLong(P[0]);
int sickleP = Integer.parseInt(P[1]);
int knutP = Integer.parseInt(P[2]);
long galleonA = Long.parseLong(A[0]);
int sickleA = Integer.parseInt(A[1]);
int knutA = Integer.parseInt(A[2]);
long galleon = 0;
int sickle = 0, knut = 0;
//模拟减法公式
if(knutA >= knutP)
knut = knutA - knutP;
else{
//借位
knutA += 29;
sickleA --;
knut = knutA - knutP;
}
if(sickleA >= sickleP)
sickle = sickleA - sickleP;
else{
//借位
sickleA += 17;
galleonA --;
sickle = sickleA - sickleP;
}
galleon = galleonA - galleonP;
if(flag)
System.out.println("-" + galleon + "." + sickle + "." + knut);
else
System.out.println(galleon + "." + sickle + "." + knut);
}
}
运行结果:
1038、统计同成绩学生(分数 20)
题目描述:
代码实现:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, K;
int scores[101];
memset(scores, 0, sizeof(scores));
cin >> N;
for(int i = 0;i < N;i ++){
int score;
cin >> score;
scores[score] ++;
}
cin >> K;
for(int i = 0;i < K;i ++){
int score_;
cin >> score_;
cout << scores[score_];
if(i < K - 1)
cout << " ";
else
cout << endl;
}
return 0;
}
运行结果:
1039、到底买不买(分数 20)
题目描述:
代码实现:
txt = list(input())
pattern = list(input())
ss = txt[:]
flag = "Yes"
success = 0
fail = 0
for word in pattern :
if word in ss :
ss.remove(word)
success += 1
else :
flag = "No"
fail += 1
if flag == "Yes" :
print(flag,len(txt) - success)
else :
print(flag,fail)
运行结果:
1040、有几个PAT(分数 25)
题目描述:
代码实现:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* 注意规律,符合题意的PAT单词必须得先有P(...),而后有A(...)再是T(...)
* 分别定义P、PA、PAT作为符合要求的‘P’、‘P...A...’、‘P...A...T...’单词
* P是PA能匹配成功的保障,PA是PAT能匹配成功的保障,所以后一条件满足时需累加上前面已满足要求的字符数
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String s = bf.readLine();
bf.close();
int P = 0, PA = 0, PAT = 0;
for (char c: s.toCharArray()) {
if (c == 'P') P ++;
else if (c == 'A') PA = (PA + P) % 1000000007;
else if (c == 'T') PAT = (PAT + PA) % 1000000007;
}
System.out.println(PAT);
}
}
运行结果: