{"id":5660,"date":"2022-10-09T08:49:59","date_gmt":"2022-10-08T23:49:59","guid":{"rendered":"https:\/\/suzutukiblog.com\/?p=5660"},"modified":"2022-10-17T10:02:41","modified_gmt":"2022-10-17T01:02:41","slug":"tips-9","status":"publish","type":"post","link":"https:\/\/suzutukiblog.com\/index.php\/2022\/10\/09\/tips-9\/","title":{"rendered":"TIPS(Ruby:\u6587\u5b57\u5217+\u6570\u5024\u3092\u6570\u5024\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\u3059\u308b)"},"content":{"rendered":"<h3>\u76ee\u6a19\uff1a\u306a\u306b\u304c\u3057\u305f\u3044\u304b\uff1f<\/h3>\n<p>\u6587\u5b57\u5217+\u6570\u5024\u3092\u6570\u5024\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\u3059\u308b<\/p>\n<h3>\u554f\u984c<\/h3>\n<p>\u3068\u3042\u308bWeb\u30b5\u30fc\u30d3\u30b9\u306e\u30e6\u30fc\u30b6\u30fc ID \u306f\u300c\u30e6\u30fc\u30b6\u30fc\u30cd\u30fc\u30e0 + \u30b7\u30ea\u30a2\u30eb\u30ca\u30f3\u30d0\u30fc\u300d\u3068\u306a\u308a\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001satou\u3055\u3093\u304c1\u756a\u76ee\u306b\u767b\u9332\u3057\u305f\u5834\u5408\u3001\u30e6\u30fc\u30b6\u30fc ID \u306f\u300csatou1\u300d\u3001<br \/>\nsuzuki\u3055\u3093\u304c 1081 \u756a\u76ee\u306b\u767b\u9332\u3057\u305f\u5834\u5408\u3001\u30e6\u30fc\u30b6\u30fc ID \u306f\u300csuzuki1081\u300d\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3044\u307e\u3001\u3053\u306e Web\u30b5\u30fc\u30d3\u30b9\u306b\u767b\u9332\u3057\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u306e\u3046\u3061 N \u4eba\u306e\u30e6\u30fc\u30b6\u30fc ID \u304c\u4e0e\u3048\u3089\u308c\u308b\u306e\u3067\u3001\u305d\u308c\u3089\u3092\u756a\u53f7\u306e\u82e5\u3044(\u5c0f\u3055\u3044)\u9806\u306b\u4e26\u3079\u3066\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<dl class=\"txt1\">\n<dt class=\"icon4\">\u6761\u4ef6<\/dt>\n<dd>\u30fb1 \u884c\u76ee\u306b\u30e6\u30fc\u30b6\u30fc ID \u306e\u500b\u6570\u3092\u8868\u3059\u6574\u6570 N \u304c\u4e0e\u3048\u3089\u308c\u307e\u3059\u3002(1 \u2266 N \u2266 200)<br \/>\n\u30fb\u540d\u524d\u306f\u5168\u3066\u82f1\u5c0f\u6587\u5b57\u306e\u307f\u304b\u3089\u306a\u308a\u307e\u3059<br \/>\n\u30fb\u30b7\u30ea\u30a2\u30eb\u30ca\u30f3\u30d0\u30fc\u306f\u5168\u3066 1 \u4ee5\u4e0a 100 \u4ee5\u4e0b\u306e\u6574\u6570\u3067\u3001\u5148\u982d\u306b\u4e0d\u8981\u306a 0 \u3092\u542b\u307f\u307e\u305b\u3093\u3002<br \/>\n\u30fb\u30b7\u30ea\u30a2\u30eb\u30ca\u30f3\u30d0\u30fc\u306f\u30e6\u30cb\u30fc\u30af\u306a\u306e\u3067\u540c\u3058\u756a\u53f7\u306f\u306a\u3044\u3067\u3059\u3002<\/p>\n<h3>\u4e0e\u3048\u3089\u308c\u308b\u5165\u529b\u5024<\/h3>\n<\/dd>\n<\/dl>\n<pre>5\r\nsatou1\r\nsuzuki1081\r\ntanaka990\r\nyamada100\r\nkawase1001<\/pre>\n<h3>\u671f\u5f85\u3059\u308b\u51fa\u529b<\/h3>\n<pre>satou1\r\nyamada100\r\ntanaka990\r\nkawase1001\r\nsuzuki1081<\/pre>\n<h3>\u30b3\u30fc\u30c9\u3068\u89e3\u8aac<\/h3>\n<pre>#\u5165\u529b\u5024(\u6570\u5024)\u3092\u53d7\u3051\u53d6\u308b\r\nn = gets.to_i\r\n\r\n#\u7a7a\u306e\u914d\u5217\u3092\u4f5c\u6210\u3059\u308b\r\nary,answer = [],[]\r\n\r\n#n\u56de\u7e70\u308a\u8fd4\u3059\r\nn.times do |i|\r\n  #2\u884c\u540d\u4ee5\u964d\u306e\u5165\u529b\u5024\u3092<strong>\u6587\u5b57\u5217\u3068\u3057\u3066<\/strong>\u53d7\u3051\u53d6\u308b\r\n  user_id = gets.chomp \r\n\r\n  #<strong>\u6570\u5b57\u306e\u624b\u524d\u30672\u3064<\/strong>\u306b\u5206\u5272\u3059\u308b\r\n  user_id = user_id.split(\/(?=\\d)\/,2)\r\n  \r\n  #\u5206\u5272\u3057\u305f\u3082\u306e\u306e\u6570\u5b57\u304c\u6587\u5b57\u5217\u306e\u307e\u307e\u306a\u306e\u3067\u6570\u5024\u306b\u5909\u63db\u3059\u308b\r\n  user_id[1] = user_id[1].to_i\r\n  \r\n  #\u7a7a\u306e\u914d\u5217ary\u306buser_id\u3092\u683c\u7d0d\u3057\u3066\u3044\u304f\r\n  ary &lt;&lt; user_id\r\nend\r\n#\u914d\u5217\u3092<strong>\u6570\u5b57\u306e<\/strong>\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\r\nary = ary.sort_by{ |_, number| number }\r\n\r\n#\u6587\u5b57\u5217\u3068\u6570\u5b57\u3092\u7e4b\u3052\u30661\u884c\u305a\u3064\u51fa\u529b\r\nn.times { |i| puts ary[i].join }<\/pre>\n<h2><a href=\"https:\/\/paiza.io\/ja\/projects\/new\">https:\/\/paiza.io\/ja\/projects\/new<\/a><\/h2>\n<h2>\u2191\u3053\u3061\u3089\u306b\u30b3\u30d4\u30da\u3057\u3066\u300c\u5b9f\u884c\u300d\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/h2>\n<h2>\u2193\u3053\u306e\u3088\u3046\u306a\u51fa\u529b\u7d50\u679c\u306b\u306a\u3063\u3066\u3044\u308c\u3070OK\u3067\u3059\u3002<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5671\" src=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/09\/d2041dd0b4019f4423818eb5ad65c77f.png\" alt=\"\" width=\"185\" height=\"227\" \/><\/p>\n<h2>\u203b ary = ary.sort_by{ |_, number| number }\u304c\u30dd\u30a4\u30f3\u30c8<\/h2>\n<pre><code class=\"stdout ng-binding\">[[\"satou\", 1], [\"suzuki\", 1081], [\"tanaka\", 990], [\"yamada\", 100], [\"kawase\", 1001]]<\/code><\/pre>\n<h2>\u914d\u5217\u306e0\u756a\u76ee\u306e\u6587\u5b57\u5217\u3067\u4e26\u3073\u66ff\u3048\u305a\u306b<\/h2>\n<h2>\u914d\u5217\u306e1\u756a\u76ee\u306e\u6570\u5024\u3092\u57fa\u6e96\u306b\u3057\u3066\u6607\u9806\u306b\u4e26\u3073\u66ff\u3048\u3066\u3044\u308b\u3002<\/h2>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6a19\uff1a\u306a\u306b\u304c\u3057\u305f\u3044\u304b\uff1f \u6587\u5b57\u5217+\u6570\u5024\u3092\u6570\u5024\u306e\u6607\u9806\u306b\u30bd\u30fc\u30c8\u3059\u308b \u554f\u984c \u3068\u3042\u308bWeb\u30b5\u30fc\u30d3\u30b9\u306e\u30e6\u30fc\u30b6\u30fc ID \u306f\u300c\u30e6\u30fc\u30b6\u30fc\u30cd\u30fc\u30e0 + \u30b7\u30ea\u30a2\u30eb\u30ca\u30f3\u30d0\u30fc\u300d\u3068\u306a\u308a\u307e\u3059\u3002 \u4f8b\u3048\u3070\u3001satou\u3055\u3093\u304c1\u756a\u76ee\u306b\u767b\u9332\u3057\u305f\u5834\u5408\u3001\u30e6\u30fc\u30b6\u30fc I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[27,31,32],"tags":[],"class_list":["post-5660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-note","category-ruby","category-tips"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/5660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=5660"}],"version-history":[{"count":4,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/5660\/revisions"}],"predecessor-version":[{"id":5662,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/5660\/revisions\/5662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/media\/2684"}],"wp:attachment":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=5660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=5660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=5660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}