加拿大信息竞赛 2015 junior problem 4 WAIT TIME
2016-01-30 22:40
525 查看
package junior2015;
import java.io.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/*
*
* 方法1:用hashmap解决
*
* */
class MyTimer {
public int sytle;
public int time;
}
public class Junior2015p4 {
public static void main(String[] args) throws Exception {
// File f=new File("C://Users//lenovo//Desktop//hello.txt");
// BufferedReader br1=new BufferedReader(new FileReader(f));
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int sum=Integer.parseInt(str);
int count=0;
String letter=" ";
String friend=" ";
//一开始是0为时间开始算,总时间为time
int time=1;
//输入处理
//用hashmap实现
Map<String,MyTimer> map=new HashMap<String,MyTimer>();
while(true)
{
//程序输入进行处理
if(count==sum)
{
break;
}
str=br.readLine();
String strline[]=str.split(" ");
letter= strline[0];
friend= strline[1];
///////////////////////////////////
//输入为w情况
if(letter.equals("W"))
{
//w后面跟着的是总时间
time=time+Integer.parseInt(friend)-1;
}
else{
time++;
}
//用Map实现
if(letter.equals("R"))
{
if(map.get(friend)==null)
{
MyTimer temp=new MyTimer();
temp.sytle=0;
temp.time=time;
map.put((String)friend,temp);
}
else{
map.get(friend).time=time;
}
}
//有s的此时为全部的time
if(letter.equals("S"))
{
map.get(friend).sytle=map.get(friend).sytle+time-map.get(friend).time;
map.get(friend).time=-1;
}
count++;
}
System.out.println();
//输出处理
//排序处理
Map<String,MyTimer> sortmap=new TreeMap<String,MyTimer>(new MapKeyComparator());
sortmap.putAll(map);
for(Map.Entry<String,MyTimer> entry:sortmap.entrySet())
{
if(entry.getValue().time==-1)
System.out.println(entry.getKey() + " " + entry.getValue().sytle);
else
System.out.println(entry.getKey() + " " + -1);
}
}
}
class MapKeyComparator implements Comparator<String>{
@Override
public int compare(String str1, String str2) {
return str1.compareTo(str2);
}
}
import java.io.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/*
*
* 方法1:用hashmap解决
*
* */
class MyTimer {
public int sytle;
public int time;
}
public class Junior2015p4 {
public static void main(String[] args) throws Exception {
// File f=new File("C://Users//lenovo//Desktop//hello.txt");
// BufferedReader br1=new BufferedReader(new FileReader(f));
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int sum=Integer.parseInt(str);
int count=0;
String letter=" ";
String friend=" ";
//一开始是0为时间开始算,总时间为time
int time=1;
//输入处理
//用hashmap实现
Map<String,MyTimer> map=new HashMap<String,MyTimer>();
while(true)
{
//程序输入进行处理
if(count==sum)
{
break;
}
str=br.readLine();
String strline[]=str.split(" ");
letter= strline[0];
friend= strline[1];
///////////////////////////////////
//输入为w情况
if(letter.equals("W"))
{
//w后面跟着的是总时间
time=time+Integer.parseInt(friend)-1;
}
else{
time++;
}
//用Map实现
if(letter.equals("R"))
{
if(map.get(friend)==null)
{
MyTimer temp=new MyTimer();
temp.sytle=0;
temp.time=time;
map.put((String)friend,temp);
}
else{
map.get(friend).time=time;
}
}
//有s的此时为全部的time
if(letter.equals("S"))
{
map.get(friend).sytle=map.get(friend).sytle+time-map.get(friend).time;
map.get(friend).time=-1;
}
count++;
}
System.out.println();
//输出处理
//排序处理
Map<String,MyTimer> sortmap=new TreeMap<String,MyTimer>(new MapKeyComparator());
sortmap.putAll(map);
for(Map.Entry<String,MyTimer> entry:sortmap.entrySet())
{
if(entry.getValue().time==-1)
System.out.println(entry.getKey() + " " + entry.getValue().sytle);
else
System.out.println(entry.getKey() + " " + -1);
}
}
}
class MapKeyComparator implements Comparator<String>{
@Override
public int compare(String str1, String str2) {
return str1.compareTo(str2);
}
}
相关文章推荐
- 部署OpenStack问题汇总(三)--Failed to add image
- 1014. Waiting in Line (30)
- 解密Google Deepmind AlphaGo围棋算法:真人工智能来自于哪里?
- 【观点】语言交流将是人工智能拟人化的核心
- 人工智能-搜索算法
- failed to push some refs to git
- Error 42 error C2784: 'bool std::operator <(const std::_Tree<_Traits>
- Error 42 error C2784: 'bool std::operator <(const std::_Tree<_Traits>
- HDU——1789Doing Homework again(贪心)
- HashMap的resize和Fail-Fast机制
- putty登录,提示no supported authentication methods available解决方法
- cf#22-B-Bargaining Table-枚举+贪心+dp(最大连续区间和)
- [leetcode] 220. Contains Duplicate III 解题报告
- Linux -磁盘管理 ip http://blog.csdn.net/xh16319/article/details/17272455
- Email List
- UVa442 Matrix Chain Multiplication(栈)
- 使用Genymotion安装APK出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE的解决办法
- HDU 1021:Fibonacci Again
- Location of several networks in brain
- hdoj 1789 Doing Homework again