compare items by array

  1. $KCODE='SJIS'
  2. a=[]
  3. ha={}
  4. File.open("103.txt").each_line{ |l|
  5. a.push(l.strip.chomp.to_i)#number
  6. }
  7. a.sort!
  8. af=File.open("103.txt","w")
  9. af.puts(a)
  10. af.close()
  11. b=[]
  12. File.open("102.txt").each_line{|l|
  13. b.push(l.strip.chomp.to_i)#number
  14. }
  15. b.sort!
  16. bf=File.open("102.txt","w")
  17. bf.puts(b)
  18. bf.close()
  19. cc=File.open("same.txt","w")
  20. cc.puts(a & b)
  21. dd=File.open("diff.txt","w")
  22. dd.puts( b.size()>a.size()?(b-a):(a-b))#compare from - compare to
  23. =begin
  24. 102.txt
  25. -------
  26. 10
  27. 5
  28. 8
  29. 103.txt
  30. -------
  31. 30
  32. 5
  33. 20
  34. 8
  35. diff.txt
  36. -------
  37. 20
  38. 30
  39. =end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值