吃过猪肉也要见识猪跑步 level
获赞
10
粉丝
7
关注
4
看过 TA
2
广州大学
2020
C++
IP属地:广东
暂未填写个人简介
私信
关注
2019-05-06 21:05
广州大学 C++
第一道:100% s = input() count = 0 stack = [] for c in s: if not stack: stack.append(c) continue if c == stack[-1]: del stack[-1] count += 1 else: stack.append(c) print(count) 第二道:40%,直接print(0)的话,70% n, k = list(map(int, input().split())) x = list(...
nq1994:四题都ac了 代码如下 package demo; import java.util.ArrayList; import java.util.Deque; import java.util.HashMap; import java.util.Queue; import java.util.Scanner; import java.util.Stack; public class Main {               void fun1() {         Scanner scan=new Scanner(System.in);         String str=scan.next();         int s=0;         Stack<Character>st=new Stack<Character>();         for(int i=0;i<str.length();i++) {             Character ch=str.charAt(i);             if(!st.empty()&&st.peek().equals(ch)) {                 st.pop();                 s++;             }else {                 st.add(ch);             }         }         System.out.println(s);     }          void fun2() {         Scanner scan=new Scanner(System.in);         long m;         int n;                  m=scan.nextLong();         n=scan.nextInt();         long s=m;         for(int i=0;i<n;i++) {             long x=scan.nextInt();             x=m-x;             s=s-x;         }                  if(s<=0) {             s=0;         }         System.out.println(s);     }          void fun3() {         Scanner scan=new Scanner(System.in);         int n,k;         int []arr=new int[20000];         n=scan.nextInt();         k=scan.nextInt();         HashMap<Integer, Integer>map=new HashMap<Integer, Integer>();         for(int i=0;i<n;i++) {             int x=scan.nextInt();             int y=scan.nextInt();             x=x*2;             y=y*2;             for(int j=x;j<=y;j++)                 arr[j]+=1;         }                  int t1=0,t2=0;         ArrayList<Integer>arr1=new ArrayList<Integer>();         ArrayList<Integer>arr2=new ArrayList<Integer>();         for(int i=0;i<20000;i++)         {             if(arr[i]>=k) {                 //System.out.println(i);                 arr[i]=k;                 if(i==0||arr[i-1]!=k) {                     t1=i;                 }             }             else if(i>0&&arr[i-1]==k) {                 t2=i-1;                 arr1.add(t1);                 arr2.add(t2);             }         }                  System.out.println(arr1.size());         for(int i=0;i<arr1.size();i++) {             System.out.println(arr1.get(i)/2+" "+arr2.get(i)/2);         }     }          void fun4() {         Scanner scan=new Scanner(System.in);         int m=scan.nextInt();         int n=scan.nextInt();         ArrayList<Integer> arr=new ArrayList<Integer>();         for(int i=0;i<m;i++) {             int x=scan.nextInt();             arr.add(x);         }         arr.sort(null);                           long s=0;         long min=arr.get(m-1)*n;         for(int i=0;i<=m-n;i++)cf         {             long max=arr.get(i+n-1);             if(i==0) {                 for(int j=i;j<i+n;j++) {                     s+=arr.get(j);                 }             }else {                 s=s-arr.get(i-1)+arr.get(i+n-1);                              }             //System.out.println("max="+max+"s="+s);             long x=max*n-s;             if(x<min) {                 min=x;             }         }                  System.out.println(min);     }          public static void main(String[] args) {         // TODO Auto-generated method stub                  Main demo=new Main();         demo.fun4();              } }
投递拼多多集团-PDD等公司10个岗位 >
0 点赞 评论 收藏
分享
关注他的用户也关注了:
牛客网
牛客企业服务