模板一
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader reader;
static BufferedWriter writer;
public static void main(String[] args) throws Exception {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(reader.readLine());
for (int i = 0; i < T; i++) {
solve();
}
reader.close();
writer.close();
}
static void solve() throws IOException {
String[] s = reader.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int m = Integer.parseInt(s[1]);
writer.write("ans" + "\n");
}
}
模板二
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
for (int i = 0; i < T; i++) {
String s = sc.nextLine();
s = s.substring(0, s.length() / 2);
Set<Character> set = new HashSet<>();
for (char c : s.toCharArray()) {
set.add(c);
}
System.out.println(set.size() == 1 ? "NO" : "YES");
}
}
}
示例一(A. Watermelon)
题目地址
题目截图
提交方式
可以提交本地文件,也可以在线提交。我们这里选择在线提交方式,点击上图中的 SUBMIT 按钮,会进入如下界面。
输入Java代码效果如下:
然后可以直接在输入框中编辑代码,完成后点击底部的 Submit,然后会进入以下界面。如果编译错误或者答案错误,可以点击 Verdict 列的链接查看具体失败原因。
示例代码
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if (sc.hasNext()) {
int n = Integer.parseInt(sc.next());
System.out.println(n > 2 && n % 2 == 0 ? "YES" : "NO");
}
sc.close();
}
}
示例二(A. Way Too Long Words)
题目地址
题目截图
示例代码
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
String s = br.readLine();
bw.write(s.length() > 10 ? abbreviation(s) : s);
bw.newLine();
}
br.close();
bw.close();
}
private static String abbreviation(String s) {
return s.charAt(0) + ("" + (s.length() - 2)) + s.charAt(s.length() - 1);
}
}