这是成长值那题的java代码,但是没有AC,我这里处理输入结束符用了scanner.nextLine().equals("")去判断是否为空,但是没过;我用了一个map来存储每一行的内容,当然任务成长值我没有累加,题意好像也没说要累加,每日成长值累加了,求AC过了的大神指点
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();
		int sum = 0;
		String str = null;
		while(!(str = sc.nextLine()).equals(""))
		{
			String[] s = str.split(" ");
			int length = s.length;
			if(s[0].equals("1"))
			{
				int start = Integer.parseInt(s[1]);
				int end = Integer.parseInt(s[2]);
				for(int i = start; i <= end; i++)
				{
					if(!map.containsKey(i))
					{
						map.put(i,Integer.parseInt(s[3]));
					}
					else
					{
						int temp = map.get(i);
						if(Integer.parseInt(s[3]) > temp)
							map.put(i,Integer.parseInt(s[3]));
						else 
							continue;
					}
				}
			}
			else if(s[0].equals("2"))
			{
				if(!map.containsKey(Integer.parseInt(s[1])))
					map.put(Integer.parseInt(s[1]), Integer.parseInt(s[2]));
				else
				{
					int temp = map.get(Integer.parseInt(s[1]));
					temp = temp + Integer.parseInt(s[2]);
					map.put(Integer.parseInt(s[1]),temp);
				}
			}
		}
		Iterator it = map.entrySet().iterator();
		while(it.hasNext())
		{
			Map.Entry<Integer,Integer> entry = (Map.Entry<Integer, Integer>)it.next();
			Integer i = entry.getValue();
			sum += i;
	    }
		System.out.println(sum);
	}
}