迟来的每日se训练

import java.util.*;

//编写代码,以给定值x为基准将链表分割成两部分,所有小于x的结点排在大于或等于x的结点之前

class ListNode {
int val;
ListNode next = null;

ListNode(int val) {    this.val = val;}

}
public class Partition {
public ListNode partition(ListNode pHead, int x) {
// write code here
ListNode bs = null;
ListNode be = null;
ListNode as = null;
ListNode ae = null;
while (pHead != null) {
if(pHead.val < x) {
if(bs == null) {
bs = pHead;
be = pHead;
}else {
be.next = pHead;//此时的cur已经是循环过一次的
be = be.next;//把be和be.next一起往后移
}
}else {
if(as == null) {
as = pHead;
ae = pHead;
}else {
ae.next = pHead;
ae = ae.next;
}
}
pHead = pHead.next;
}
/*
把新的链表串起来
1、两个段内 可能有一个是空的
如果as不等于空,ae.next = null;
2、如果两个段都有数据
be.next = as;
*/
if(bs == null) {
return as;
}
/else(as == null) {
return bs;
}if(bs != null && as != null) {
be.next = as;
ae.next = null;
}
return bs;
/
if(bs != null) {
be.next = as;
if (as != null) {
ae.next = as;
}
}
return bs;
}
}

import java.util.Arrays;

public class Gift {
public int getValue(int[] gifts, int n) {
// write code here
Arrays.sort(gifts);
int check = gifts[gifts.length/2];
int count = 0;
for (int i = 0;i < gifts.length;i ) {
if (gifts[i] == check) {
count ;
}
}
if (count > gifts.length/2) {
return check;
}else return 0;
}

public static void main(String[] args) {    int[] gifts = {1,5,5,4,4,5,5,};    int n = gifts.length;    Gift gift = new Gift();    System.out.println(gift.getValue(gifts,n));}

}

import java.util.ArrayList;

import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
//查找和排序 查找和排序 题目:输入任意(用户,成绩)序列,可以获得成绩从高到低或从低到高的排列
// ,相同成绩都按先录入排列在前的规则处理。
private static class Student {
private String name;
private int score;

    private Student(String name,int score){        this.name = name;        this.score = score;    }}public static void main(String[] args) {    Scanner sc=new Scanner(System.in);    while(sc.hasNext()){        int numPeople=sc.nextInt();        int option=sc.nextInt();        List<Student> list = new ArrayList<>();        for(int i=0;i<numPeople;i  ){            list.add(new Student(sc.next(),sc.nextInt()));        }        if(option==0){            list.sort((o1, o2) -> o2.score - o1.score);        }else if(option==1){            list.sort((o1,o2) ->o1.score-o2.score);            //list.sort(Comparator.comparingInt(o -> o.score));        }        for(Student stu : list){            System.out.println(stu.name " " stu.score);        }    }}

// Scanner sc = new Scanner(System.in);
// while (sc.hasNext()) {
// int n = sc.nextInt();
// int t = sc.nextInt();
// Student[] students = new Student[n];
// for (int i = 0; i < n; i ) {
// String name = sc.nextLine();
// int score = sc.nextInt();
// students[i] = new Student(name, score);
// }
// if (t == 1) {
// for (int i = 0;i < n;i ) {
// for (int j = i 1; j < n;j ) {
// if (students[i].score > students[j].score) {
// Student student1 = new Student(students[j].name,students[j].score);
// students[j] = students[i];
// students[i] = student1;
// }
// }
// }
//
// }
// if (t == 0) {
// for (int i = 0;i < n;i ) {
// for (int j = i 1; j < n;j ) {
// if (students[i].score < students[j].score) {
// Student student1 = new Student(students[i].name,students[i].score);
// students[i] = students[j];
// students[j] = student1;
// }
// }
// }
// }
// StringBuilder sb = new StringBuilder();
// for (Student s : students) {
// sb.append(s.name).append(" ").append(s.score).append(’\n’);
// }
// System.out.print(sb.toString());
// }
}

import java.util.Arrays;

class Substr1 {
//请设计一个高效算法,对于p中的每一个较短字符串,判断其是否为s的子串.
static boolean[] chkSubStr(String[] p, int n, String s) {
boolean[] tf = new boolean[n];
for (int i = 0; i < n; i ) {
tf[i] = s.contains(p[i]);
}
return tf;
}

public static void main(String[] args) {    String s = "abcwea";    String[] p = {"a","b","c","q"};    int n = 4;    System.out.println(Arrays.toString(chkSubStr(p, n, s)));}

}

public class Substr {
//请设计一个高效算法,对于p中的每一个较短字符串,判断其是否为s的子串.
public boolean check(String s1,String s2) {
int i = 0;
while (i s1.length() <= s2.length()-1) {
int a = i;
int count = a s1.length();
StringBuilder sb = new StringBuilder();
sb.append(s2.substring(a,count));
if (sb.toString().equals(s1))
return true;
i ;
}
return false;
}
public boolean[] chkSubStr(String[] p, int n, String s) {
// write code here
boolean[] bn = new boolean[n] ;
for (int i = 0;i < n;i ) {
bn[i] = check(p[i],s);
}
return bn;

}public static void main(String[] args) {    Substr substr = new Substr();    String[] p = {"a","b","c"};    int n = 3;    String s = "abc";    System.out.println(Arrays.toString(substr.chkSubStr(p, n, s)));}

}

import java.util.Scanner;

class dd{
public int foo(int x,int y) {
if (x<=0 || y<=0) {
return 1;
}
return 3*foo(x-6,y/2);
}
}

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String a = sc.nextLine();
char[] b = a.toCharArray();
for(int i = 0;i< b.length;i ){
char c = b[i];
if(c-‘A’>=0){
c =(char)( c >‘E’? (c-5): (c 21));
b[i] = c;
}
}
}
}
// while (sc.hasNext()) {
// String s = sc.nextLine().toUpperCase();
// char[] ch = s.toCharArray();
// for(int i = 0;i< ch.length;i ) {
// char c = ch[i];
// if (ch[i] < ‘A’) {
// break;
// }
// if (c >= ‘A’) {
// c = (char) (c > ‘E’ ? (c - 5) : (c 21));
// ch[i] = c;
// }
// }
// StringBuilder sb = new StringBuilder();
// sb.append(ch.toString().split(" "));
// System.out.println();
// }

}
//兔子生孩子构成的斐波那契额数列
class ain {
public static int get(int c){
if (c == 1 || c == 2) {
return 1;
}
return get(c-1) get(c-2);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int c = sc.nextInt();
System.out.println(get©);
}
}
}

import java.util.Scanner;

class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
//实现一个函数,检查二叉树是否平衡,平衡的定义如下,对于树中的任意一个结点,其两颗子树的高度差不超过1。
//给定指向树根结点的指针TreeNode*root,请返回一个bool,代表这棵树是否平衡.
class Balance {
public boolean isBalance(TreeNode root){
if(root == null){
return true;
}
int left = getTreeHeight(root.left);
int right = getTreeHeight(root.right);
if(Math.abs(left - right) > 1){
return false;
}
return isBalance(root.left) && isBalance(root.right);
}

private int getTreeHeight(TreeNode root) {    if(root == null){        return 0;    }    return Math.max(getTreeHeight(root.left),getTreeHeight(root.right)) 1;}

}

//给定-系列正整数,请按要求对数字进行分类,
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0;i < n;i ){
a[i] = sc.nextInt();
}
int sum0 = 0;int c0 = 0;
int cc = 1;int sum1 = 0;int c1 = 0;
int count = 0;int c2 = 0;
int sum3 = 0;int c3 = 0;
int tmp = 0;int c4 = 0;
for (int i = 0;i < a.length;i ) {
if (a[i]%5 == 0) {
if (a[i]%2 == 0) {
c0 ;
sum0 = a[i];
}
}else if (a[i]%5 == 1) {
c1 ;
sum1 = sum1 cc*a[i];
cc = -1^c1;
}else if (a[i]%5 == 2) {
count ;
c2 ;
}else if (a[i]%5 == 3) {
sum3 =a[i];
c3 ;
}else if (a[i]%5 == 4) {
c4 ;

                if (a[i] > tmp) {                    tmp = a[i];                }            }        }        if (c0 != 0) {            System.out.print(sum0 " ");        } else {            System.out.print("N" " ");        }        if (c1 != 0) {            System.out.print(sum1 " ");        } else {            System.out.print("N" " ");        }        if (c2 != 0) {            System.out.print(count " ");        } else {            System.out.print("N" " ");        }        if (c3 != 0) {            System.out.print(1.0*sum3/c3 " ");        } else {            System.out.print("N" " ");        }        if (c4 != 0) {            System.out.println(tmp);        } else {            System.out.println("N");        }    }}

}

import java.util.Scanner;

class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
//实现一个函数,检查二叉树是否平衡,平衡的定义如下,对于树中的任意一个结点,其两颗子树的高度差不超过1。
//给定指向树根结点的指针TreeNode*root,请返回一个bool,代表这棵树是否平衡.
class Balance {
public boolean isBalance(TreeNode root){
if(root == null){
return true;
}
int left = getTreeHeight(root.left);
int right = getTreeHeight(root.right);
if(Math.abs(left - right) > 1){
return false;
}
return isBalance(root.left) && isBalance(root.right);
}

private int getTreeHeight(TreeNode root) {    if(root == null){        return 0;    }    return Math.max(getTreeHeight(root.left),getTreeHeight(root.right)) 1;}

}

//给定-系列正整数,请按要求对数字进行分类,
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0;i < n;i ){
a[i] = sc.nextInt();
}
int sum0 = 0;int c0 = 0;
int cc = 1;int sum1 = 0;int c1 = 0;
int count = 0;int c2 = 0;
int sum3 = 0;int c3 = 0;
int tmp = 0;int c4 = 0;
for (int i = 0;i < a.length;i ) {
if (a[i]%5 == 0) {
if (a[i]%2 == 0) {
c0 ;
sum0 = a[i];
}
}else if (a[i]%5 == 1) {
c1 ;
sum1 = sum1 cc*a[i];
cc = -1^c1;
}else if (a[i]%5 == 2) {
count ;
c2 ;
}else if (a[i]%5 == 3) {
sum3 =a[i];
c3 ;
}else if (a[i]%5 == 4) {
c4 ;

                if (a[i] > tmp) {                    tmp = a[i];                }            }        }        if (c0 != 0) {            System.out.print(sum0 " ");        } else {            System.out.print("N" " ");        }        if (c1 != 0) {            System.out.print(sum1 " ");        } else {            System.out.print("N" " ");        }        if (c2 != 0) {            System.out.print(count " ");        } else {            System.out.print("N" " ");        }        if (c3 != 0) {            System.out.print(1.0*sum3/c3 " ");        } else {            System.out.print("N" " ");        }        if (c4 != 0) {            System.out.println(tmp);        } else {            System.out.println("N");        }    }}

}

来源:https://www.icode9.com/content-4-816601.html

(0)

相关推荐

  • ​LeetCode刷题实战236:二叉树的最近公共祖先

    算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试.所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 ! 今天和大家 ...

  • 每日一题 剑指offer(从上往下打印二叉树)

    编程是很多偏计算机.人工智能领域必须掌握的一项技能,此编程能力在学习和工作中起着重要的作用.因此小白决定开辟一个新的板块"每日一题",通过每天一道编程题目来强化和锻炼自己的编程能力 ...

  • ​LeetCode刷题实战298:二叉树最长连续序列

    算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试.所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 ! 今天和大家 ...

  • 每日一题 剑指offer(二叉树中和为某一值的路径)

    编程是很多偏计算机.人工智能领域必须掌握的一项技能,此编程能力在学习和工作中起着重要的作用.因此小白决定开辟一个新的板块"每日一题",通过每天一道编程题目来强化和锻炼自己的编程能力 ...

  • (1条消息) 万字长文!二叉树入门和刷题看这篇就够了!

    今天是小浩算法 "365刷题计划" 二叉树入门 - 整合篇.本篇作为入门整合篇,已经砍去难度较大的知识点,所有列出的内容,均为必须掌握.因为很长,写下目录: 二叉树是啥 二叉树的最 ...

  • 视唱练耳每日基本功训练:模唱

    视唱练耳每日基本功训练:模唱

  • 深蹲是“动作之王”,每日坚持训练,有哪些益处?

    深蹲是"动作之王",每日坚持训练,有哪些益处? 塑身联盟 发布时间: 2021.08-0920:23 无论是正在健身的朋友还是有计划健身的朋友,或许他们都听说过,动作训练之王深蹲. ...

  • 每日阅读训练|《西游记》相关知识考点

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...

  • 每日阅读训练|《骆驼祥子》中的女性角色

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...

  • 每日阅读训练|《傅雷家书》中的父子情深

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...

  • 每日阅读训练|《傅雷家书》苦心孤诣的教子篇

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...

  • 每日阅读训练|《骆驼祥子》相关知识考点

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...

  • 每日阅读训练|《海底两万里》的科幻与现实

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...

  • 每日阅读训练|《水浒传》林冲相关考点

    新课标改革的不断推进,以阅读为中心的考试形态已渐趋明显. 应试机制下的阅读行为主要关联在考场阅读层面,涉及阅读积累.阅读理解.阅读鉴赏3个层级,新课改后,阅读行为已经伸展为包括阅读与梳理.阅读与交流. ...