importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){int sum =0;Scanner scanner =newScanner(System.in);char[] str = scanner.next().toCharArray();int j,k=0;for(int i =0; i<str.length;i++){//寻找右边界for(j = i+1;j<str.length;j++){if(str[i]== str[j])break;}for(k = i-1;k>=0;k--){//寻找左边界if(str[i]== str[k])break;}
sum +=(i-k)*(j-i);}System.out.println(sum);}}
会问日期-第十一届蓝桥杯
importjava.util.Scanner;publicclassMain{staticint[] mo =newint[]{0,31,28,31,30,31,30,31,31,30,31,30,31};// 定义月份,判断日期是否合法的时候会用到publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);int num = scanner.nextInt();boolean flag =false;for(int i = num+1;i<=99999999;i++){String data =Integer.toString(i);//转换为字符串int year = i/10000;//年int month = i%10000/100;// 月int day = i%100;//日if(check(year, month, day)&&huiwen(data)){if(!flag){System.out.println(data);
flag =true;}if(ABAB(data)){System.out.println(data);break;}}}}//判断ABABpublicstaticbooleanABAB(String data){char[] str = data.toCharArray();return str[0]== str[2]&& str[1]== str[3];}//判断回文publicstaticbooleanhuiwen(String data){StringBuffer stringBuffer =newStringBuffer(data);String string = stringBuffer.reverse().toString();return data.equals(string);}//判断日期是否正确publicstaticbooleancheck(int year,int month,int day){if(month>12||month<1)// 若月不合法就返回falsereturnfalse;if(year %400==0||(year %4==0&& year%100!=0)){
mo[2]=29;}else mo[2]=28;return day <= mo[month]&& day >=1;}}
成绩分析-第十一届蓝桥杯
importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);int n = scanner.nextInt();int[] nums =newint[n];int maxNum =Integer.MIN_VALUE;int minNum =Integer.MAX_VALUE;float sum =0;for(int i =0;i<n;i++){
nums[i]= scanner.nextInt();}for(int i =0;i<n;i++){
maxNum =Math.max(maxNum,nums[i]);
minNum =Math.min(minNum,nums[i]);
sum += nums[i];}System.out.println(maxNum);System.out.println(minNum);System.out.printf("%.2f",sum/n);}}
时间显示-第十二届蓝桥杯
importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);long n = scanner.nextLong();
n = n/1000;
n = n %(24*60*60);//剩下一天的时间long h = n/3600;long m = n/60%60;long s = n%60;System.out.printf("%02d:",h);System.out.printf("%02d:",m);System.out.printf("%02d",s);}}
双向排序-第十二届蓝桥杯
importjava.util.Arrays;importjava.util.Comparator;importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);int n = scanner.nextInt();int m = scanner.nextInt();Integer[] num =newInteger[n];for(int i =0;i<n;i++) num[i]= i+1;for(int i=0;i<m;i++){int control = scanner.nextInt();int index = scanner.nextInt();MyComparator cmpComparator =newMyComparator();if(control ==0){//前面nums[i][1]降序排列Arrays.sort(num,0, index,cmpComparator);}else{Arrays.sort(num,index-1,num.length);}}for(int a :num){System.out.print(a+" ");}}}classMyComparatorimplementsComparator<Integer>{@Overridepublicintcompare(Integer o1,Integer o2){if(o1 > o2)return-1;elseif(o1 < o2)return1;elsereturn0;}}
importjava.util.ArrayList;importjava.util.HashSet;importjava.util.Scanner;importjava.util.Set;publicclassMain{publicstaticvoidmain(String[] args){Scanner scan =newScanner(System.in);Set<Integer> set =newHashSet<>();int n = scan.nextInt();int[] nums =newint[n];for(int i =0; i<n;i++){
nums[i]= scan.nextInt();}
set.add(0);//加入0是为了将砝码的重量加入for(int i =0;i<n;i++){ArrayList<Integer> list =newArrayList<>(set);for(int k:list){//set是有序不可重复的,所以可以直接进行加减不需要考虑去重
set.add(k+nums[i]);
set.add(Math.abs(k-nums[i]));}}
set.remove(0);System.out.println(set.size());}}
货物摆放-第十二届蓝桥杯
importjava.util.ArrayList;importjava.util.HashSet;importjava.util.Set;publicclassMain{publicstaticvoidmain(String[] args){long n =2021041820210418l;Set<Long> set =newHashSet<>();for(long i =1;i<=Math.sqrt(n);i++){if(n%i==0){
set.add(i);if(n/i!=i) set.add(n/i);}}int counrt =0;ArrayList<Long> list =newArrayList<Long>(set);for(long i =0;i<set.size();i++){for(long j =0;j<set.size();j++){for(long k =0;k<set.size();k++){if(list.get((int) i)*list.get((int) j)*list.get((int) k)== n) counrt ++;}}}System.out.println(counrt);}}
importjava.util.*;publicclassMain{publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);double n = sc.nextInt();if(n <=21){double x =f(n);double y =f(n+1);double ratio =(double)(x/y);System.out.println(String.format("%.8f", ratio));}else{System.out.println(0.61803399);}}publicstaticdoublef(double n){if(n ==1|| n ==2){return1;}returnf(n-1)+f(n-2);}}
平方和-第十届
importjava.util.*;publicclassMain{publicstaticvoidmain(String[] args){HashSet<Character> set =newHashSet<>();HashSet<Integer> set2 =newHashSet<>();
set.add('0');
set.add('1');
set.add('2');
set.add('9');for(int i =1; i<=2019;i++){String s =Integer.toString(i);//System.out.println(s);for(int j =0; j<s.length();j++){if(set.contains(s.charAt(j))){
count++;
set2.add(i);break;}}}long sumh =0l;List<Integer> list =newArrayList<>(set2);for(int i =0; i<list.size();i++){int temp = list.get(i);
sumh += temp*temp;}System.out.println(sumh);}}
packagehello;importjava.util.*;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);int n = scanner.nextInt();int[] nums =newint[n];for(int i =0;i<n;i++){
nums[i]= scanner.nextInt();}int res =Integer.MIN_VALUE;//每一层的和int depth =0;//深度int count =0;//最后的深度int index =0;//索引boolean flag =true;while(flag){
depth ++;int sum =0;//每一次的和0for(int j =0; j<Math.pow(2,depth-1);j++){if(index >= n){
flag =false;break;}
sum += nums[index++];}if(res < sum){
res = sum;
count = depth;}}System.out.println(count);}}
外卖优先级-第十届
packagehello;importjava.util.*;publicclassMain{staticScanner in =newScanner(System.in);staticint n, m, t;staticMap<Integer,ArrayList<Integer>> map =newTreeMap<Integer,ArrayList<Integer>>();staticint result;publicstaticvoidmain(String[] args){
n = in.nextInt();
m = in.nextInt();
t = in.nextInt();for(int i =1; i <= m;++i){int time = in.nextInt();int id = in.nextInt();if(map.containsKey(id)){
map.get(id).add(time);}else{ArrayList<Integer> temp =newArrayList<Integer>();
temp.add(time);
map.put(id, temp);}}ArrayList<Map.Entry<Integer,ArrayList<Integer>>> list =newArrayList<Map.Entry<Integer,ArrayList<Integer>>>(
map.entrySet());for(int i =0; i < list.size();++i){//商户Map.Entry<Integer,ArrayList<Integer>> entry = list.get(i);//商户对应的订单时间ArrayList<Integer> list2 = entry.getValue();//取出value 订单时间int level =0;//优先级int[] count =newint[t +2];boolean flag =false;for(int j =0; j < list2.size();++j)
count[list2.get(j)]++;//这个时刻的订单数for(int j =1; j <= t;++j){if(count[j]==0){if(level >0)
level--;if(level <=3)
flag =false;}else{
level += count[j]*2;if(level >5)
flag =true;}}if(flag)
result++;}System.out.println(result);}}
修改数组-第十届
importjava.util.*;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);int n = scanner.nextInt();int[] nums =newint[n];for(int i =0; i<n;i++){
nums[i]= scanner.nextInt();}HashSet<Integer> set =newHashSet<>();
set.add(nums[0]);for(int i =1; i<n;i++){while(set.contains(nums[i])){
nums[i]++;}
set.add(nums[i]);}for(int num:nums){System.out.println(num);}}}
importjava.util.Scanner;publicclassMain{staticint[] a =newint[100010];staticint[] f =newint[100010];staticint n;staticScanner cin =newScanner(System.in);publicstaticvoidmain(String[] args){// TODO 自动生成的方法存根// 初始化f数组为它本身for(int i =1; i <=100009; i++){
f[i]= i;}
n = cin.nextInt();for(int i =1; i <= n; i++){
a[i]= cin.nextInt();
a[i]=find(a[i]);
f[a[i]]=find(a[i]+1);}for(int i =1; i <= n; i++){System.out.print(a[i]+" ");}}staticintfind(int x){if(f[x]== x){return x;}else{
f[x]=find(f[x]);return f[x];}}}
publicclassMain{//1901年1月1日至2000年12月31日之间//一年365,闰年有366//一周7天//算闰年publicstaticvoidmain(String[] args){int count =0;//闰年个数for(int i =1901;i<2001;i++){if(i %400==0||(i %4==0&& i %100!=0)){
count ++;}}//计算一百年一共多少天int sum =(100-count)*365+ count*366;int total = sum/7;//System.out.println(count);System.out.println(total);}}