2024-07-01ãã1ã¶æéã®è¨äºä¸è¦§
æååã®é¨åæååãåå¾ããé¢æ° substr() (C++) ãç¨ããããfor æã§æ¸ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æåå "atcoder" ã«ã¤ãã¦ã æåç®ãã æåç®ã¾ã§ãåºåããã å¶ç´ è§£æ³ (1)ï¼é¢æ° substr() ã使ãã æåå S ã«å¯¾ãã¦ã S.substr(i, l) ã¯â¦
æ¡ä»¶ãå·§ã¿ã«è¨ãæãã¦æ´çãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 3 åã®æ´æ° ãä¸ããããã ãã¡ãã£ã¢ã³ã§ãããã©ãããå¤å®ããã è§£æ³ ãã¡ãã£ã¢ã³ã¨ã¯ãããªãã¡ã ãå°ããé ã«ä¸¦ã¹ãã¨ãã«ã ã 2 çªç®ã«å°ããã¨ãããã¨ã§ããããã®ãããªå ´å㯠ãâ¦
ã·ãã¥ã¬ã¼ã·ã§ã³ã§è§£ãããæ°å¦çã«è§£ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã·ã£ã³ãã¼ã mL ä½ã£ã¦ããã F ãããM ãããT ãããé ã« mL ãã¤ä½¿ã£ã¦ãããæåã«ã·ã£ã³ãã¼ã足ããªããªã人ã誰ã«ãªãããæ±ããã è§£æ³ (1)ï¼ã·ãã¥ã¬ã¼ã·ã§ã³ ã¾ãã¯ãã·ã£â¦
if æã並ã¹ãæããswitch æã使ãããªããããã§ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ Monday, Tuesday, Wednesday, Thursday, Friday ã®ããããã®æåå ãä¸ããããããããããæææ¥ãç«ææ¥ãæ°´ææ¥ãæ¨ææ¥ãéææ¥ã表ãã ãã®æ¥ããåææ¥ã¾ã§ä½æ¥ã§â¦
æååã®ããæãã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æå 'A' ã åã'B' ã åãâ¦ã'Z' ã åããã®é ã«ç¹ãã¦å¾ãããæååã®å é ãã çªç®ã®æåãæ±ãã¦ãã ããã å¶ç´ èããã㨠å®éã«æååãä½ãããã® çªç®ã«ã¢ã¯ã»ã¹ããã°ããã å®éã«æååâ¦
ãã¢å¤ã®å¤§å°æ¯è¼ããããã¯ãåãã«æç®ããæãããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é«æ©å㯠æ åã«èµ·ãã¦ãéæ¨å㯠æ å 1 ç§ã«èµ·ããã é«æ©åã®èµ·åºæå»ãéæ¨åããæ©ããªãã° Takahashi ããããã§ãªããªãã° Aoki ãåºåããã èããã㨠ãã¢å¤ ã¨â¦
確çãèããããã®åºç¤ã¨ãªãåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã³ã³ãã¹ãã« 1000 人ãåå ããã ä¸ä½ ä½ã¯ã確å®ã« T ã·ã£ãããããã ä¸ä½ ä½ãã ä½ã¾ã§ã¯ããã®ä¸ããã©ã³ãã 㫠人ãé¸ã°ãã¦ãT ã·ã£ãããããã ãã以å¤ã¯ãT ã·ã£ããããããªã â¦
è½ã¡çãã¦æ´çãã¦ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã®æå°ã® 4 ã§å²ã£ã¦ 2 ä½ãæ´æ°ãæ±ããã å¶ç´ èããã㨠ã 4 ã§å²ã£ãä½ãã«ãã£ã¦å ´ååããã¦èãããã ã 4 ã§å²ãåããã¨ãï¼2 足ããã¨ã§ã4 ã§å²ã£ã¦ 2 ä½ãæ´æ°ãã«ãªãã®ã§ã ãçãâ¦
æå¾ã®åºåãå°ãããããããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 21:00 ã® åå¾ã®æå»ã "22:14" ã®ãããªå½¢å¼ã§åºåããã å¶ç´ è§£æ³ ã¾ãã¯æå»ãæ±ãããã ã®ã¨ãã¯ã æ å ã®ã¨ãã¯ã æ å ã¨æ±ããããã ãã¦ãåºåããã¨ãã«ã¯ãä½åãã®ã¨ãâ¦
ãããã char åã®æ±ãæ¹ã«é¢ããåé¡ã¯ãããé£ããåé¡ã§ã¯å½ããåã®ããã«ç»å ´ããã®ã§ãä»ã®ãã¡ã«æ £ãã¦ããããã§ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è±å°æå a, b, â¦, z ã® ASCII æåã³ã¼ãã¯ãã®é ã« 97, 98, â¦, 122 ã§ããã 97 ä»¥ä¸ 122 以ä¸ã®æ´â¦
for æã®ç·´ç¿ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ° ãä¸ããããã ã®å¤ãæ±ããã è§£æ³ ã¾ããçãã表ãå¤æ° res ãç¨æãã¾ããã (åæå¤ã¯ 0 ã¨ãã¾ã)ã for æãç¨ãã¦ãé ã« A[i] ã res ã«è¶³ãè¾¼ãã§ããã¾ãã ã³ã¼ã #include <bits/stdc++.h> using namespace s</bits/stdc++.h>â¦
for æã§æ±ãã¦ããããã1 << N ã¨ããããã«ãããã·ããæ¼ç®åãç¨ãã¦ã解ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 0 以ä¸ã®æ´æ° ãä¸ããããã ã®å¤ãæ±ããã å¶ç´ è§£æ³ (1)ï¼for æ ã¯ã ã åããããã®ãã§ãã åãããå¦ç㯠for æã§å®è£ ã§ãã¾ãã 注â¦
æ´æ°ã¨ãã¦æ±ã£ã¦ã解ãããã©ãæååã¨ãã¦å¦çããã®ã楽ã ã¨æãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 100 以ä¸ã® 3 æ¡ã®æ´æ° ãä¸ããããã®ã§ã ã®ä¸äºæ¡ãåºåããã è§£æ³ 3 æ¡ã®æ´æ°å¤ãæåå N ã¨ãã¦å ¥åãåãåããããã¨ãã°ã459 ã¨ããæ´æ°ã¯ã"459" â¦
äºæ¬¡å é åã®ç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ã¨ã2 è¡ 2 åãããªãè¡å ãä¸ããããã®ã§ã ãåºåããã è§£æ³ 2 è¡ 2 åã®è¡åã¯ã次ã®ãã㪠2 次å ã®é åã§å®è£ ã§ããã int A[2][2]; ããããã¨ã è¡ç® åç®ã®è¦ç´ ã¯ãA[R][C] ã¨è¡¨ããã ã³â¦
ã®å¶ç´ãå°ããã®ã§ããåºéããæãåã£ã¦å ¨é¨æ¢ç´¢ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã ãæºãããã㪠ã«ã¤ãã¦ã®ã ã®å¤ã®æ大å¤ãæ±ããã å¶ç´ è§£æ³ ãã®æã®åé¡ã§æ©ãã§ãã¾ãã®ã¯ãã£ãããªãã¨è¨ãã¾ãï¼ ã¾ãã¯ãã³ã³ãâ¦
for æã§é£æ¥ããè¦ç´ ãè¦ãªããå¦çãã¦ããç³»ã®åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ãä¸ããããã ãå·¦ããè¦ã¦ãããæåå "joi" ãå«ã¾ãããªãã°ãããã "JOI" ã«å¤æãã¦ããå¦çãç¹°ãè¿ããæä½å¾ã®æååãåºåããã è§£æ³ æ¬¡ã®ããã«â¦
ããããªè§£æ³ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä»¥ä¸ ä»¥ä¸ã®æ´æ°ã®ãã¡ã ã¨ã®å·®ã®çµ¶å¯¾å¤ãæãå°ãããã®ãæ±ããã å¶ç´ è§£æ³ (1)ï¼for æ ä¸çªç¢ºå®ãªæ¹æ³ã¯ãfor æãç¨ãã¦ã ããã¹ã¦èª¿ã¹ããã¨ã ã¨æããã¾ãã ãæå°ã¨ãªããã㪠ãæ±ããã°ããã§ãâ¦
éè¨å¦çãç·´ç¿ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä»¥ä¸ ä»¥ä¸ã®æ´æ°ãããªããé·ã ã®æ°å ãä¸ããããã é·ã ã®æ°ããªæ°å ã次ã®ããã«å®ç¾©ããã å ã«å¯¾ãã¦ã ãã ãæºãã ã®åæ° ã®æ大å¤ãæ±ããã å¶ç´ è§£æ³ åé¡ã®æå³ã解éããã®ãé£ããããâ¦
reverse ããç³»ã®åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ã«ã¤ãã¦ã æåç®ãã æåç®ã¾ã§ãå転ãã¦å¾ãããæååãåºåããã å¶ç´ è§£æ³ C++ ã§ããã°ã©ã ãæ¸ãã¨ãã¯ãé常æåå㯠0 å§ã¾ãã§ãã®ã§ã ããããããã 1 å¼ãã¦ããã¾ãã ãã®â¦
ãã¼ã¸ã½ã¼ãã®ãã¼ã¸ã®é¨åãå®è£ ããåé¡ã§ããã æ·»åãé ã«é²ãã¦ãããããªå¦çãå®è£ ãã¾ãï¼ ãã®å®è£ ã¯ãã®ã¡ã«ãããã¨ãæ³ãå¦ã¶éã®åèã«ããªãã¾ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å¶ç´ è§£æ³ åé¡æãè¤éã§ãä½ãããã°ããã®ããç解ããã®ã大å¤â¦
å°ãé¢ç½ãåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ãã 1, 2, 3 ã®ããããã®æåå ãä¸ããããã ãç¹°ãè¿ãã¦å¾ãããæååã§ãã£ã¦ãé·ãã 6 ã§ãããã®ãçããã èããã㨠次ã®ããã«èããã°è¯ãã ã®é·ãã 1 ã®ã¨ãï¼ ã 6 åç¹°ãè¿ã ã®é·ãã 2 â¦
ä¸æã«è§£éãã¦åé¡ã解ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 0 㨠1 ã®ã¿ãããªãé·ã 4 ã®æåå ãä¸ããããããã®æååã¯ã4 ãã¹ãããªãåãã¹ã«äººããããã©ããã表ãã ã¯ãã®ãã¹ã«äººããããã¨ã表ãã ã¯äººãããªããã¨ã表ãã ä»ã人ãã¿ãªå³ã¸ç§»â¦
for æã®ç·´ç¿ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ãä¸ããããã ã®ãã¡æ¯é³åã®åæ°ãã¤ã¾ã aï¼iï¼uï¼eï¼o ã®åæ°ã®ç·åãæ±ããã è§£æ³ æåå ã®æåã 1 åãã¤ãfor æã使ã£ã¦èª¿ã¹ã¦ããã¾ãããã ã³ã¼ã #include <bits/stdc++.h> using namespace std; int</bits/stdc++.h>â¦
楽ããåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 3 åã®æ´æ° ãä¸ããããã ãããã®æ´æ°ã®ãã¡ã大ããæ¹ãã 2 åã®åãæ±ããã è§£æ³ ããããä¸çªå°ããæ°ããå¼ãã°è¯ãã§ãããã ã®ãã¡ä¸çªå°ããæ°ã¯ãC++ ã§ã¯ãé¢æ° min() ãç¨ã㦠min({A, B, C}) ã¨è¡¨ãâ¦
å¤é for æã«æ £ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ã¨ãé·ã ã®æ°å ãä¸ããããã ãæºããæ´æ°ã®çµ ã®åæ°ãæ±ããã å¶ç´ è§£æ³ å¤é for æã«æ £ãã¾ãããï¼ æ°å ã® çªç®ã¨ãæ°å ã® çªç®ããã¹ã¦èª¿ã¹ãã®ã¯ã次ã®ãã㪠2 éã® for æã§è¨â¦
for æã®ã«ã¼ãã«ã¦ã³ã¿ ãå¶æ°ãå¥æ°ãã«å¿ãã¦å¦çãå¤ããåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ããå¥æ° ã®æåå ãä¸ããããã ãã®æååã«å¯¾ãã¦ã次ã®æä½ããããã¨ã§ã"IOIOIO...OI" ã¨ããããã« "I" 㨠"O" ãç¹°ãè¿ãæååã«ããããæä½åæ°ã®â¦
é¢æ° max() ã¨é¢æ° min() ã使ãããªããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 2 ã¤ã®æ´æ° ãä¸ããããã 㨠ã®ãã¡ãæ大ã®ãã®ã¨æå°ã®ãã®ãé ã«åºåããã è§£æ³ ã¾ãã 㨠ã®ãã¡ã®æ大ã®ãã®ã¯ max(A + B, A - B) ã¨è¡¨ãã¾ãããªãã 㨠ãåãå¤ã§ããå ´åã«ã¯â¦
for æã®ç·´ç¿ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å (ãã¹ã¦ã®è¦ç´ ã¯äºãã«ç¸ç°ãªã) ã«ã¤ãã¦ãæ大å¤ãèããã¨ãããã®å·¦å´ã®ç·åã¨ãå³å´ã®ç·åãããããæ±ããã å¶ç´ è§£æ³ ãã®åé¡ã§ã¯ãæ°å ã®æ大å¤ã ãã§ã¯ãªã ãæ大ã¨ãªããã㪠ãæ±ããå¿ â¦
å¤é for æã®å ¨æ¢ç´¢ã«æ £ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ãä¸ããããã次ã®æ¡ä»¶ãæºãã 3 ã¤çµã®æ´æ° ãåå¨ãããã©ãããå¤å®ããã ã® æåç®ã¯ 'I' ã§ãã ã® æåç®ã¯ 'O' ã§ãã ã® æåç®ã¯ 'I' ã§ãã å¶ç´ è§£æ³ ãæºãããã㪠â¦
ã¡ãã£ã¨ç´°ããã¨ãããã¹ã£ã人ãå¤ããããããªããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã太éã¯å¸°çãããã¨ã«ããã ä»æ¥ãã æ¥å¾ã®ååã«å®å®¶ã«çããä»æ¥ãã æ¥å¾ã®ååã«å®å®¶ãå»ãã ãããèãã¤ããããåã¯ãä»æ¥ãã æ¥å¾ã®åå¾ã«ã太éã®å®å®¶ã訪ãâ¦