2014-01-27 155 views
1

我正在研究一个项目,我在其中完成了所有的努力工作,但仍然存在一些我不知道要解决的问题。在阵列中格式化

我有一个包含行数据的数组,其中每行代表一个数组单元格,X,Y是变量并可能更改。

x GETFIELD 
x PUTFIELD 
y GETFIELD 
y PUTFIELD 

我需要找出有多少个get-field for x和put-field for x,其余的变量也是一样的。

x , 1 get-field , 1 put-field 

y , 1 get-field , 1 put-field 

total get-field:2 , total put-field:2 

,或者给出了同样的分析,任何格式。

感谢

+0

你只需要算的出现? – Leo

+0

'Collections.frequency' http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#frequency(java.util.Collection,java.lang.Object) –

回答

0

我想你需要两个地图,一个为得到和其他看跌期权。关键将是变量,并且地图值将是一个计数器,每次发现事件时都会增加计数器。

例如,在伪代码:

declare maps puts and gets 
for(items of your array){ 
    split variable and command 
    if command = getfield{ 
     if (gets.get(variable) == null){ 
      gets.put(variable,0) 
     } 
     gets.get(variable)++ 
    }else{ 
     if (puts.get(variable) == null){ 
      puts.put(variable,0) 
     } 
     puts.get(variable)++ 
    } 
} 
+0

i don'吨得到它,你可以给一个例子plz – user2214408

+0

例子伪代码给出 – Leo