Map_iterator & min()

package com.test;

import java.util.HashMap;
import java.util.Map;

public class Test3
{
    public String test(Map<String, Integer> temp)
    {
        Object[] tempArray = temp.values().toArray();
        int[] countArray = new int[tempArray.length];

        for (int i = 0; i < tempArray.length; i++)
        {
            countArray[i] = (Integer)tempArray[i];
        }
        
        int min = countArray[0];
        for (int i = 0; i < countArray.length; i++)
        {
            if (min > countArray[i])
            {
                min = countArray[i];
            }
        }
        
        for (Map.Entry<String, Integer> entry : temp.entrySet())
        {
            if (entry.getValue().intValue() == min)
            {
                return entry.getKey();
            }
        }
        return null;
    }
    
    public static void main(String[] args)
    {
        Test3 test = new Test3();
        Map<String, Integer> coolMap = new HashMap<String, Integer>();
        coolMap.put("101", 12);
        coolMap.put("102", 1);
        coolMap.put("103", 4);
        coolMap.put("104", 2);
        coolMap.put("105", 6);
        coolMap.put("106", 5);
        coolMap.put("107", 12);
        coolMap.put("108", 345);
        String rs = test.test(coolMap);
        System.out.println(rs);
    }
}

 Map<String, Integer> temp

 

        for (Map.Entry<String, Integer> entry : temp.entrySet())
        {
            System.out.println(entry.getKey() + entry.getValue());
        }

 

=======================

int[] countArray = ~~~~~~

int min = countArray[0];
for (int i = 0; i < countArray.length; i++)
{
    if (min > countArray[i])
   {
        min = countArray[i];
    }
}

======

 

const ServerParam & SP = ServerParam::i(); const int self_min = wm.interceptTable()->selfReachCycle(); const int mate_min = wm.interceptTable()->teammateReachCycle(); int opp_min = wm.interceptTable()->opponentReachCycle(); const PlayerObject * opp_fastest = wm.interceptTable()->fastestOpponent(); if ( opp_fastest && opp_fastest->goalie() && wm.gameMode().isPenaltyKickMode() && opp_fastest->pos().dist( wm.ball().pos() ) >= 3.0 ) // MAGIC NUMBER { M_tackle_situation = false; M_opponent_ball = false; dlog.addText( Logger::TEAM, __FILE__":(update) penalty shootouts. not a tackle situation" ); return; } if ( opp_fastest && wm.gameMode().isPenaltyKickMode() && ! opp_fastest->goalie() ) { const AbstractPlayerObject * opponent_goalie = wm.getTheirGoalie(); if ( opponent_goalie ) { /* //yz del std::map< const AbstractPlayerObject*, int >::const_iterator player_map_it = wm.interceptTable()->playerMap().find( opponent_goalie ); if ( player_map_it != wm.interceptTable()->playerMap().end() ) { // considering only opponent goalie in penalty-kick mode opp_min = player_map_it->second; dlog.addText( Logger::TEAM, __FILE__":(update) replaced min_opp with goalie's reach cycle (%d).", opp_min ); } else { opp_min = 1000000; // practically canceling the fastest non-goalie opponent player dlog.addText( Logger::TEAM, __FILE__":%d: (update) set opp_min as 1000000 so as not to consider the fastest opponent.", __LINE__ ); } */ } else { opp_min = 1000000; // practically canceling the fastest non-goalie opponent player dlog.addText( Logger::TEAM, __FILE__":%d (update) set opp_min as 1000000 so as not to consider the fastest opponent.", __LINE__); } }
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值