乐信3AC,第二道AC取巧了

import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        for (int i = 1; i <= m; ++i) {

            int temp = n;
            temp = temp - i;
            if (temp % (m + 1) == 0) {
                System.out.println("win " + i);
                return;
            }
        }
        System.out.println("lose");

    }
}

//第三道


 public static int kSum(int A[], int k, int target) {
        int count = 0;
        if(k == 2) {
            for(int i=0;i < A.length - 1;++i) {
                for(int j=i+1;j < A.length;++j) {
                    if(A[i] + A[j] == target) {
                        ++count;
                    }
                }
            }
        } else if(k == 3) {
            for(int i=0;i < A.length - 1;++i) {
                for(int j=i+1;j < A.length;++j) {
                    for(int m=j+1;m < A.length;++m) {
                        if(A[i] + A[j] + A[m] == target) {
                            ++count;
                        }
                    }
                    
                }
            }
        }
        return count;
    }

//第二道这样做会被打死不

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] strs = str.split("-");
        Map<Integer, Integer> map = new LinkedHashMap<>();
        for(int i = 0;i < strs.length;++i) {
            int row = Integer.parseInt(strs[i]);
            if(!map.containsKey(row)) {
                map.put(row, 1);
            } else {
                int temp = map.get(row) + 1;
                map.put(row, temp);
            }
        }
       
        while(map.size() > 0) {
             int key = 0;
             int value = 0;
            for(Integer k:map.keySet()) {
                int t = map.get(k);
                if(value < t) {
                    value = t;
                    key = k;
                } else if(value == t) {
                    if(key < k) {
                        key = k;
                        value = t;
                    } 
                } else {
                    continue;
                }
            }
            System.out.print(key+"-"+value);
            map.remove(key);
            if(map.size() > 0) {
                System.out.print(" ");
            }
        }
        
    }
}

全部评论
膜dalao
点赞 回复 分享
发布于 2017-09-24 10:27
没有吧,一次过了
点赞 回复 分享
发布于 2017-09-23 21:16
请问。第一题哪里有坑吗?
点赞 回复 分享
发布于 2017-09-23 21:11

相关推荐

notbeentak...:就抓,嗯抓,开不开匿名都要抓,一点坏事不让说,就对公司顶礼膜拜佩服的五体投地就对了
点赞 评论 收藏
分享
用微笑面对困难:你出于礼貌叫了人一声大姐,大姐很欣慰,她真把你当老弟
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务