import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
int n = in.nextInt();
int[] arr = new int[31];
for(int i = 0;i < n; i++){
int a = in.nextInt();
int b = in.nextInt();
arr[a] = b;
}
int count_a = 0;
int count_b = 0;
int now_a = 1;
int now_b = 2;
while(arr[now_a] != 0){
count_a++;
now_a = arr[now_a];
}
while(arr[now_b] != 0){
count_b++;
now_b = arr[now_b];
}
if(count_a > count_b){
System.out.println("You are my elder");
}else if(count_a < count_b){
System.out.println("You are my younger");
}else{
System.out.println("You are my brother");
}
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Solution solution = new Solution();
while(in.hasNext()){
int num = in.nextInt();
solution.drawNum(num);
}
}
}
class Solution{
public void drawNum(int num){
int space = num - 1;
int count = 0;
//上半三角
for(int i = 1;i <= num; i++){
count++;
space--;
//空格打印
for(int j = space;j >= 0; j--){
System.out.printf(" ");
}
//递增打印
for(int k = 1;k <= count; k++){
System.out.printf("%d", k);
}
//递减打印
for(int k = count - 1;k >= 1; k--){
System.out.printf("%d", k);
}
System.out.println("");
}
//下半三角
for(int i = num - 1;i >= 1; i--){
count--;
space++;
//空格打印
for(int j = space;j >= 0; j--){
System.out.printf(" ");
}
//递增打印
for(int k = 1;k <= count; k++){
System.out.printf("%d", k);
}
//递减打印
for(int k = count - 1;k >= 1; k--){
System.out.printf("%d", k);
}
System.out.println("");
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Solution solution = new Solution();
while(in.hasNext()){
char c = in.next().charAt(0);
if (!in.hasNextInt()) {
break;
}
int len = in.nextInt();
solution.drawS(c, len);
System.out.println("");
}
}
}
class Solution{
public void drawS(char c, int len){
int space = len - 1;
int p = 1;
//三角
for(int i = 1;i <= len; i++){
space--;
//空格打印
for(int j = space;j >= 0; j--){
System.out.printf(" ");
}
//递增打印
for(int k = 1;k <= p; k++){
if(i != len){
if(k == 1){
System.out.printf("%c", c);
}else if(k == p){
System.out.printf("%c", c);
}else{
System.out.printf(" ");
}
}else{
System.out.printf("%c", c);
}
}
p+= 2;
System.out.println("");
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine(); // 读取并丢弃换行符
for(int i = 0;i < n; i++){
//想要将输入的字符串按照空格进行分割,并且不包含空格子字符串。
//可以使用split("\s+")方法。
StringBuffer result = new StringBuffer();
String[] str = in.nextLine().split("\\s+");
int len = str.length;
for(int j = 0;j < len; j++){
if(str[j].charAt(0) > 'A'){
result.append(Character.toUpperCase(str[j].charAt(0)));
}else{
result.append(str[j].charAt(0));
}
}
System.out.println(result.toString());
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
for(int i = 0;i < n; i++){
StringBuilder str1 = new StringBuilder(in.nextLine());
StringBuilder str2 = new StringBuilder(in.nextLine());
int len = str1.length();
str1.insert(len / 2, str2);
System.out.println(str1);
}
}
}
没想到时隔那么久还有要写画图的代码哈哈,比大一时顺畅多了,基本随便写就行。
15题注意StringBuilder insert的用法。这时候在复习一下:
String、StringBuffer、StringBuilder的区别?
String:底层构建使用final关键字,故不可编辑。
StringBuffer:可以编辑,线程安全型,在并发时使用。
StringBuilder:可以编辑,线程不安全型,相比StringBuffer损耗小,常用。
Comments NOTHING