{"id":10691,"date":"2026-07-09T08:30:00","date_gmt":"2026-07-08T23:30:00","guid":{"rendered":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/?page_id=10691"},"modified":"2026-07-03T17:32:22","modified_gmt":"2026-07-03T08:32:22","slug":"ex1305a","status":"publish","type":"page","link":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/lecture\/prog\/exercise-advance\/ex13\/ex1305a\/","title":{"rendered":"\u8ab2\u984c [13] \u69cb\u9020\u4f53\uff085\/8\uff09"},"content":{"rendered":"<div class=\"breadcrumbs align wp-block-bcn-breadcrumb-trail has-text-color has-background\" vocab=\"https:\/\/schema.org\/\" typeof=\"BreadcrumbList\">\n\t<span><\/span>\n\t<span property=\"itemListElement\" typeof=\"ListItem\"><a property=\"item\" typeof=\"WebPage\" title=\"Go to \u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u5de5\u5b66\u7814\u7a76\u5ba4.\" href=\"https:\/\/se.cite.ehime-u.ac.jp\/jp\" class=\"home\" aria-current=\"page\"><span property=\"name\">\u30db\u30fc\u30e0<\/span><\/a><meta property=\"position\" content=\"1\"><\/span><\/div>\n\n\n\n<h4 class=\"wp-block-heading has-background\" style=\"background-color:#d3f28c\"><strong>\u554f 5<\/strong>\uff08\u63d0\u51fa\u30d7\u30ed\u30b0\u30e9\u30e0\u540d\uff1aex1305a.h\uff09<\/h4>\n\n\n\n<p class=\"problem wp-block-paragraph\">\u307e\u305a\uff0c<a href=\"\/lecture\/prog\/material\/ex1305a.c\" target=\"_blank\" rel=\"noreferrer noopener\">\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\uff08ex1305a.c\uff09<\/a>\u3068<a href=\"\/lecture\/prog\/material\/ex1305a.h\" target=\"_blank\" rel=\"noreferrer noopener\">\u30d8\u30c3\u30c0\uff08ex1305a.h\uff09<\/a>\u3092\u305d\u308c\u305e\u308c\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u306a\u3055\u3044\uff0e<br>\u305d\u3057\u3066\uff0cex1305a.h \uff08<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-strong-blue-color\">.h\u306e\u65b9<\/mark><\/strong>\u3067\u3042\u308a\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\"><strong>.c \u3067\u306f\u306a\u3044<\/strong><\/mark>\uff09\u3092\u7de8\u96c6\u3057\u3066\u6b21\u306e\u51e6\u7406\u3092\u884c\u3046\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u3057\u3066\u4ed5\u4e0a\u3052\u306a\u3055\u3044\uff0e<br><sub>\u203b\u30d8\u30c3\u30c0\u306e\u4e2d\u3067\u69cb\u9020\u4f53\u306e\u5ba3\u8a00\u304c <br><kbd>\u3000\u3000#ifndef __STRUCT_CITY<br>\u3000\u3000#define __STRUCT_CITY<\/kbd><br>\u3068<br>\u3000\u3000<kbd>#endif <\/kbd><br>\u3067\u56f2\u307e\u308c\u3066\u3044\u308b\u304c\uff0c\u3053\u308c\u306b\u3064\u3044\u3066\u306f<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">\u554f 6 \u3067\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u63aa\u7f6e\u306a\u306e\u3067\u3072\u3068\u307e\u305a\u6c17\u306b\u3057\u306a\u304f\u3066\u3088\u3044<\/mark><\/strong>\uff0e<\/sub><br><br><strong>\u3010\u76ee\u7684\u306e\u51e6\u7406\u3011<\/strong><br>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3082\u554f 4 \u3068\u540c\u3058\u30c7\u30fc\u30bf\u3092\u6271\u3046\u304c\uff0c\u6b21\u306e\u70b9\u3060\u3051\u304c\u7570\u306a\u308b\uff1a<br>main \u95a2\u6570\u3067\u547c\u3073\u51fa\u3059\u95a2\u6570\u304c <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-strong-blue-color\"><strong><kbd>sort_p<\/kbd> \u3067\u306f\u306a\u304f <kbd>sort_n<\/kbd> \u3068\u306a\u3063\u3066\u3044\u3066<\/strong><\/mark>\uff0c<br>\u95a2\u6570 <kbd>sort_n<\/kbd> \u306f <kbd>CITY<\/kbd> \u30c7\u30fc\u30bf\u306e\u914d\u5217 <kbd>cdata[]<\/kbd> \u3092<br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">\u5e02\u306e\u540d\u524d\u306e\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\uff08\u300c\u8f9e\u66f8\u5f0f\u9806\u300d\u3068\u3044\u3046\uff09\u306b\u4e26\u3079\u66ff\u3048<\/mark><\/strong>\u308b\u3082\u306e\u3068\u3059\u308b\uff0e<br><br><strong><mark style=\"background-color:#ffffda\" class=\"has-inline-color\">\u95a2\u6570 <kbd>sort_n<\/kbd> \u3092\u5b8c\u6210\u3055\u305b\uff0cex1305a.h \u306e\u307f\u3092\u63d0\u51fa<\/mark><\/strong>\u3057\u306a\u3055\u3044\uff0e<br>\u306a\u304a\uff0c<strong>\u4e26\u3079\u66ff\u3048\u306e\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306b\u306f\u554f 4 \u3067\u3082\u8aac\u660e\u3057\u305f\u30d0\u30d6\u30eb\u30bd\u30fc\u30c8\u3092\u4f7f\u7528<\/strong>\u3057\u306a\u3055\u3044\uff0e<\/p>\n\n\n\n<p class=\"hint wp-block-paragraph\"><strong>\u3010\u30d2\u30f3\u30c8\u3011<\/strong><br>\u5e02\u306e<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">\u540d\u524d\u3069\u3046\u3057\u306e\u6bd4\u8f03\u306b\u306f\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u95a2\u6570\u306e <kbd>strcmp<\/kbd> <\/mark><\/strong>\u304c\u4fbf\u5229\u3067\u3059\uff0e<br><br>\u30d0\u30d6\u30eb\u30bd\u30fc\u30c8\u306e\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408\uff0c<br>\u4f8b\u3048\u3070 <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-strong-blue-color\"><kbd>cdata[j]<\/kbd> \u3068 <kbd>cdata[j+1]<\/kbd> \u306e\u9593\u3067\u540d\u524d\u306e\u5927\u5c0f\uff08\u9806\u5e8f\uff09\u95a2\u4fc2\u3092\u6bd4\u8f03<\/mark><\/strong>\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\uff0e<br>\u3053\u306e\u5834\u5408\u3082 <kbd>if ( cdata[j] &gt; cdata[j+1] )<\/kbd> \u3068\u66f8\u304f\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u304c\uff0c<br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-strong-blue-color\"><kbd>if ( cdata[j].name &gt;  cdata[j+1].name )<\/kbd> \u3068\u3044\u3046\u6bd4\u8f03\u3082\u8aa4\u308a<\/mark><\/strong>\u3067\u3059\uff0e<br>\u306a\u305c\u306a\u3089\uff0cname \u306f\u305d\u308c\u305e\u308c char \u914d\u5217\u306e\u540d\u524d\u306a\u306e\u3067\uff0c<br>\u4e0a\u306e\u6bd4\u8f03\u306f<strong><mark style=\"background-color:#cfffd1\" class=\"has-inline-color\">\u5358\u306a\u308b\u300c\u5148\u982d\u8981\u7d20\u306e\u30a2\u30c9\u30ec\u30b9\u306e\u6bd4\u8f03\u300d\u3092\u884c\u3063\u3066\u3044\u308b\u306b\u3059\u304e\u306a\u3044<\/mark><\/strong>\u304b\u3089\u3067\u3059\uff0e<br><br>\u305d\u306e\u305f\u3081\u306b <kbd>strcmp<\/kbd> \u95a2\u6570\u3092\u4f7f\u3044\u307e\u3059\uff0e\u3053\u306e\u95a2\u6570\u306f 2 \u3064\u306e char \u914d\u5217\uff08\u6587\u5b57\u5217\uff09\u3092\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u308a\uff0c<br><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">1 \u3064\u76ee\u306e\u65b9\u304c\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\u3067 2 \u3064\u76ee\u3088\u308a\u3082\u5f8c\u308d\u306a\u3089\u3070\u6b63\u306e\u5024<\/mark>\u3092\u8fd4\u3057\u307e\u3059<\/strong>\uff0e<br>\uff08\u203b<strong>\u9006\u306a\u3089\u3070\u8ca0\u306e\u5024<\/strong>\uff0c<strong>\u540c\u3058\u306a\u3089\u3070 0 \u3092\u8fd4\u3057\u307e\u3059\uff09<\/strong><br>\u3057\u305f\u304c\u3063\u3066\uff0c<br>\u3000\u3000<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\"><kbd><strong>if ( strmp(cdata[j].name, cdata[j+1].name) &gt; 0 )<\/strong><\/kbd><\/mark><br>\u3068\u3044\u3046\u66f8\u304d\u65b9\u306b\u306a\u308a\u307e\u3059\uff0e<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u3010\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u3011\uff08\u305d\u306e\uff11\uff09<\/strong>\u203b<span style=\"color:#ff0000\" class=\"has-inline-color\">\u8d64\u5b57<\/span>\u306f\u5b9f\u884c\u6642\u306b\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3059\u308b\u5185\u5bb9<br>\uff08\u554f 4 \u3068\u540c\u3058\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\uff09<\/li>\n<\/ul>\n\n\n\n<pre class=\"example\" style=\"width: 500px; margin-top: -15pt; margin-bottom: 10px\">\u611b\u5a9b\u770c\u5185\u306e\u5e02\u306e\u4eba\u53e3\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044<span style=\"color:#00aa00\">\u23ce<\/span>\n> <span style=\"color:#ff0000\" class=\"has-inline-color\">data1304a.txt<\/span>\n<span style=\"color:#00aa00\">\u23ce<\/span>\n\u5e02\u306e\u540d\u524d\u306e\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u3068\uff1a<span style=\"color:#00aa00\">\u23ce<\/span>\n 1) Imabari<span style=\"color:#00aa00\">\u23ce<\/span>\n     (151672\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 2) Iyo<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 35133\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 3) Matsuyama<span style=\"color:#00aa00\">\u23ce<\/span>\n     (511192\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 4) Niihama<span style=\"color:#00aa00\">\u23ce<\/span>\n     (115938\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 5) Ozu<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 40575\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 6) Saijo<span style=\"color:#00aa00\">\u23ce<\/span>\n     (104791\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 7) Seiyo<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 35388\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 8) Shikokuchuo<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 82754\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n 9) Toon<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 33903\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n10) Uwajima<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 70809\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n11) Yawatahama<span style=\"color:#00aa00\">\u23ce<\/span>\n     ( 31987\u4eba)<span style=\"color:#00aa00\">\u23ce<\/span>\n\n<\/pre>\n\n\n\n<p class=\"miss wp-block-paragraph\"><strong>\u3010\u904e\u53bb\u306b\u3042\u3063\u305f\u30df\u30b9\uff08\u5b9f\u969b\u306b\u6e1b\u70b9\u3068\u306a\u308a\uff0c\u3084\u308a\u76f4\u3057\u3092\u547d\u3058\u3089\u308c\u305f\u4f8b\uff09\u3011<\/strong><br> \u25a0 <strong>\u5b9f\u884c\u306e<span class=\"tadv-color\" style=\"color:#ff0000\">\u753b\u9762\u51fa\u529b\u306e\u5185\u5bb9\u304c\u4e0a\u306e\u4f8b\u3068\u9055\u3046<\/span><\/strong>\uff08<strong><span class=\"tadv-color\" style=\"color:#0000ff\">\u304d\u3061\u3093\u3068\u78ba\u8a8d\u3057\u3066\u3044\u306a\u3044<\/span><\/strong>\uff09\uff0e<br> \u25a0 <strong><span class=\"tadv-color\" style=\"color:#0000ff\">\u30a4\u30f3\u30c7\u30f3\u30c8\u306b\u4e0d\u5099<\/span><\/strong>\u304c\u3042\u308b\uff08<a href=\"https:\/\/se.cite.ehime-u.ac.jp\/jp\/lecture\/prog\/vscode-%e4%b8%8a%e3%81%a7%e3%82%a4%e3%83%b3%e3%83%87%e3%83%b3%e3%83%88%e3%82%92%e8%87%aa%e5%8b%95%e3%81%a7%e6%8f%83%e3%81%88%e3%82%8b%e6%96%b9%e6%b3%95\/\" target=\"_blank\" rel=\"noreferrer noopener\">VSCode \u4e0a\u3067\u30a4\u30f3\u30c7\u30f3\u30c8\u3092\u81ea\u52d5\u3067\u63c3\u3048\u308b\u4f5c\u696d<\/a>\u3092\u3084\u3063\u3066\u3044\u306a\u3044\uff09\uff0e<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-very-dark-gray-color has-css-opacity has-very-dark-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<p class=\"wp-block-paragraph\">\u2190 [ <a href=\"https:\/\/se.cite.ehime-u.ac.jp\/jp\/lecture\/prog\/exercise-advance\/ex13\/ex1304a\/\">\u554f 4 (ex1304a.h)<\/a> ]<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-align-right wp-block-paragraph\"><strong>\u30df\u30b9\u304c\u7121\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u3089<\/strong>\u6b21\u306e\u554f\u984c\u3078 \u2192 [<a href=\"https:\/\/se.cite.ehime-u.ac.jp\/jp\/lecture\/prog\/exercise-advance\/ex13\/ex1306a\/\"> \u554f 6 (ex1306a.c)<\/a> ]<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u554f 5\uff08\u63d0\u51fa\u30d7\u30ed\u30b0\u30e9\u30e0\u540d\uff1aex1305a.h\uff09 \u307e\u305a\uff0c\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\uff08ex1305a.c\uff09\u3068\u30d8\u30c3\u30c0\uff08ex1305a.h\uff09\u3092\u305d\u308c\u305e\u308c\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u306a\u3055\u3044\uff0e\u305d\u3057\u3066\uff0cex1305a.h \uff08.h\u306e\u65b9\u3067\u3042\u308a\uff0c.c \u3067\u306f\u306a\u3044\uff09\u3092\u7de8\u96c6 <a class=\"more-link\" href=\"https:\/\/se.cite.ehime-u.ac.jp\/jp\/lecture\/prog\/exercise-advance\/ex13\/ex1305a\/\">&#8230; more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":10651,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-10691","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/pages\/10691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/comments?post=10691"}],"version-history":[{"count":10,"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/pages\/10691\/revisions"}],"predecessor-version":[{"id":12822,"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/pages\/10691\/revisions\/12822"}],"up":[{"embeddable":true,"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/pages\/10651"}],"wp:attachment":[{"href":"https:\/\/se.cite.ehime-u.ac.jp\/jp\/wp-json\/wp\/v2\/media?parent=10691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}