成绩分析:
import java.util.Scanner;
/**
样例
7
80
92
56
74
88
99
10
*
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int minn = 10010;
int maxn = 0;
int n = sc.nextInt();
sc.nextLine();
long sumn = 0;
for(int i=0;i<n;i++) {
int temp = sc.nextInt();
sc.nextLine();
minn = Math.min(minn,temp);
maxn = Math.max(maxn,temp);
sumn += temp;
}
double avgn = sumn/(double)n;
System.out.println(maxn);
System.out.println(minn);
System.out.printf("%.2f",avgn);
}
}
字串分值:
快速构造arraylist:new ArrayList<Integer>(Arrays.asList(i+1))
遍历set:for(char c : s)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
//计算每个字符对结果的贡献
//贡献实际上和前后一个相同字符的位置有关
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//从1开始算,这样第一个减0就是我们需要的第一个乘数
String str = sc.nextLine();
Set<Character> s = new HashSet<Character>();
HashMap<Character,ArrayList<Integer>> h = new HashMap<Character,ArrayList<Integer>>();
for(int i=0;i<str.length();i++) {
char c = str.charAt(i);
s.add(c);
if(h.containsKey(c)) {
ArrayList<Integer> temp = h.get(c);
temp.add(i+1);
}
else h.put(c, new ArrayList<Integer>(Arrays.asList(i+1)));
}
int res = 0;
for(char c : s) {
ArrayList<Integer> temp = h.get(c);
for(int j=0;j<temp.size();j++) {
int a1,a2;
if(j==0)a1 = 0;
else a1 = temp.get(j-1);
if(j==temp.size()-1)a2 = str.length()+1;
else a2 = temp.get(j+1);
int mm = (temp.get(j)-a1)*(a2-temp.get(j));
res += mm;
}
}
System.out.println(res);
}
}
回文日期
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
format.setLenient(false);
format.parse(idate);
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class Main {
static boolean isDate(String idate) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
try {
format.setLenient(false);
format.parse(idate);
}catch(Exception e) {
return false;
}
return true;
}
static boolean isABAB(String idate) {
return idate.charAt(0)==idate.charAt(2) && idate.charAt(1)==idate.charAt(3);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
n /= 10000;
String res1 = null;
String res2 = null;
for(int i=n+1;i<9999;i++) {
StringBuilder sb = new StringBuilder(i+"");
sb.reverse();
String idate = i + "" + sb;
if(res1!=null && res2!=null)break;
if(isDate(idate)) {
if(res1==null)res1 = idate;
if(isABAB(idate)) {
res2 = idate;
}
}
}
System.out.println(res1);
System.out.println(res2);
}
}
递增序列:
public class Main {
/*
VLPWJVVNNZSWFGHSFRBCOIJTPYNEURPIGKQGPSXUGNELGRVZAG
SDLLOVGRTWEYZKKXNKIRWGZWXWRHKXFASATDWZAPZRNHTNNGQF
ZGUGXVQDQAEAHOQEADMWWXFBXECKAVIGPTKTTQFWSWPKRPSMGA
BDGMGYHAOPPRRHKYZCMFZEDELCALTBSWNTAODXYVHQNDASUFRL
YVYWQZUTEPFSFXLTZBMBQETXGXFUEBHGMJKBPNIHMYOELYZIKH
ZYZHSLTCGNANNXTUJGBYKUOJMGOGRDPKEUGVHNZJZHDUNRERBU
XFPTZKTPVQPJEMBHNTUBSMIYEGXNWQSBZMHMDRZZMJPZQTCWLR
ZNXOKBITTPSHEXWHZXFLWEMPZTBVNKNYSHCIQRIKQHFRAYWOPG
MHJKFYYBQSDPOVJICWWGGCOZSBGLSOXOFDAADZYEOBKDDTMQPA
VIDPIGELBYMEVQLASLQRUKMXSEWGHRSFVXOMHSJWWXHIBCGVIF
GWRFRFLHAMYWYZOIQODBIHHRIIMWJWJGYPFAHZZWJKRGOISUJC
EKQKKPNEYCBWOQHTYFHHQZRLFNDOVXTWASSQWXKBIVTKTUIASK
PEKNJFIVBKOZUEPPHIWLUBFUDWPIDRJKAZVJKPBRHCRMGNMFWW
CGZAXHXPDELTACGUWBXWNNZNDQYYCIQRJCULIEBQBLLMJEUSZP
RWHHQMBIJWTQPUFNAESPZHAQARNIDUCRYQAZMNVRVZUJOZUDGS
PFGAYBDEECHUXFUZIKAXYDFWJNSAOPJYWUIEJSCORRBVQHCHMR
JNVIPVEMQSHCCAXMWEFSYIGFPIXNIDXOTXTNBCHSHUZGKXFECL
YZBAIIOTWLREPZISBGJLQDALKZUKEQMKLDIPXJEPENEIPWFDLP
HBQKWJFLSEXVILKYPNSWUZLDCRTAYUUPEITQJEITZRQMMAQNLN
DQDJGOWMBFKAIGWEAJOISPFPLULIWVVALLIIHBGEZLGRHRCKGF
LXYPCVPNUKSWCCGXEYTEBAWRLWDWNHHNNNWQNIIBUCGUJYMRYW
CZDKISKUSBPFHVGSAVJBDMNPSDKFRXVVPLVAQUGVUJEXSZFGFQ
IYIJGISUANRAXTGQLAVFMQTICKQAHLEBGHAVOVVPEXIMLFWIYI
ZIIFSOPCMAWCBPKWZBUQPQLGSNIBFADUUJJHPAIUVVNWNWKDZB
HGTEEIISFGIUEUOWXVTPJDVACYQYFQUCXOXOSSMXLZDQESHXKP
FEBZHJAGIFGXSMRDKGONGELOALLSYDVILRWAPXXBPOOSWZNEAS
VJGMAOFLGYIFLJTEKDNIWHJAABCASFMAKIENSYIZZSLRSUIPCJ
BMQGMPDRCPGWKTPLOTAINXZAAJWCPUJHPOUYWNWHZAKCDMZDSR
RRARTVHZYYCEDXJQNQAINQVDJCZCZLCQWQQIKUYMYMOVMNCBVY
ABTCRRUXVGYLZILFLOFYVWFFBZNFWDZOADRDCLIRFKBFBHMAXX
*/
public static void main(String[] args) {
int a = 2;
int b = 4;
Scanner sc = new Scanner(System.in);
char[][] m = new char[a][b];
for(int i=0;i<a;i++) {
String str = sc.nextLine();
for(int j=0;j<b;j++) {
char c = str.charAt(j);
m[i][j] = c;
}
}
int res = 0;
for(int i=0;i<a;i++) {
for(int j=0;j<b;j++) {
for(int k=i+1;k<a;k++) {
if(m[i][j]<m[k][j])res++;
}
for(int k=j+1;k<b;k++) {
if(m[i][j]<m[i][k])res++;
}
//右下
for(int k=1;i+k<a&&j+k<b;k++) {
if(m[i][j]<m[i+k][j+k])res++;
}
//右上
for(int k=1;i-k>=0&&j+k<b;k++) {
if(m[i][j]!=m[i-k][j+k])res++;
}
}
}
System.out.println(res);
}
}
平方拆分
public class Main {
static int res = 0;
static void f(int n,int cur) {
cur = cur+n*n;
//System.out.println(cur);
if(cur>2019)return;
if(cur==2019)res++;
for(int i=n+1;i<50;i++) {
f(i,cur);
}
}
public static void main(String[] args) {
for(int i=1;i<50;i++) {
f(i,0);
}
System.out.println(res);
}
}res+=(s.size()-1);