é åï¼
ç´ æ°ãæ±ããã¨ããã°ããµã¤ãã¯エラトステネスのふるいã§ãããããã«ã¯é åã使ããªããã°ãªãã¾ãããããããããããã¡ã¤ã«ã«é åã¯ããã¾ãããã§ã¯ã©ãããã°ããã§ãããããããªã®ã¯ã©ãã§ããããã
@echo off for /L %%i in (1, 1, 10) do set /a a%%i = %%i echo %a1% %a2% %a3% %a4% %a5% %a6% %a7% %a8% %a9% %a10%
1 2 3 4 5 6 7 8 9 10
ããã§ç¢ºãã«a1ããa10ã«å¤ã代å
¥ããã¦ãã¾ãããããããã§ã¯ã¤ã³ããã¯ã¹ãå¤æ°ã«ãã¦ã¯å¤ãåãåºãããã«ããã¾ãããã
å®ã¯ãããã¯æ¬¡ã®ããã«ããã°å¯è½ã§ãã
for /L %%i in (1, 1, 10) do set /a s += "a%%i" echo %s%
55
"a%%i"ã§ãããã¾ãå¼ç¨ç¬¦ã®ä¸ãå±éããã¦"a1"ãªã©ã¨ãªãã¾ããããã¦ãset /aã®ä¸ã§ã¯å¼ç¨ç¬¦ã®ä¸ãè©ä¾¡ããã¦ã%a1%ã¨åçã«ãªãã¾ãã
注æããªããã°ãªããªãã®ã¯ãset /aã§ããå¤ãåãåºããªãã®ã§ããã®é
åãã©ãã«ã¯å®è³ªæ´æ°ããæ ¼ç´ã§ããªãã¨ãããã¨ã§ãã
以ä¸ã§ã¯ã2次å
以ä¸ã®ãã¨ãèãã¦ã
a_0, a_1
ã¨ãã¾ããããããã¦é åã®å¤§ããã¯ã
set /a a.size = 2
ãªã©ã¨ãããã¨ã«ãã¾ãã
ãã¦ãã¨ã©ãã¹ããã¹ã®ãµããã§ãããæºåãå¿
è¦ã§ããã¾ããæåã«é
åããã¹ã¦1ã§åæåããå¿
è¦ãããã¾ããC++ã¨std::fillã¨åããããªé¢æ°ãä½ãã¾ããããååã¯vector_fillã¨ãã¾ãã注æãã¦ããããã®ã¯ãããã§ã¯setlocalã¯ä½¿ããªããã¨ã§ããé
åã®è¦ç´ ã«ä»£å
¥ãã¦ããã®ã§ã¯ãªããå®éã«ã¯æ°ããªå¤æ°ãä½ã£ã¦ãããããsetlocalã使ãã¨ãã®å¤æ°ãå¤ã§ã¯ä½¿ããªããã¨ã«ãªãã¾ããå¤æ°ãä»ã¨ãã¶ãå¯è½æ§ãããã®ã§ã極åå¼æ°ããã®ã¾ã¾ä½¿ã£ã¦ãã¾ããã¤ãã§ã«ãããã°ã®ããã«é
åã®è¦ç´ ããã¹ã¦è¡¨ç¤ºããprint_vectorãä½ã£ã¦ããã¾ãã
@echo off set /a a.size = 10 call :fill_vector a 1 call :print_vector a exit /b 0 :fill_vector set /a max_index = "%1.size" - 1 for /L %%i in (0, 1, %max_index%) do set /a %1_%%i = %2 exit /b 0 :print_vector setlocal set vector=%1 set /a size = "%vector%.size" echo %size% if %size% == 0 echo %2 & exit /b 0 set /a e = "%vector%_0" set s=%e% set /a k = 1 :loop_print_vector if %k% == %size% echo %s% & exit /b 0 set /a e = "%vector%_%k%" set s=%s% %e% set /a k += 1 goto :loop_print_vector
10 1 1 1 1 1 1 1 1 1 1