zoukankan      html  css  js  c++  java
  • 横竖两个数字塔的效果BAT批处理怎么写?

    横竖两个数字塔的效果BAT批处理怎么写?
    @echo off
    for /l %%a in (0,1,1) do (
            for /l %%i in (0,1,9) do (
            for /l %%j in (0,1,%%i) do set /p=%%j<nul
            echo=
            )
    )
    pause

    我这个BAT可以竖下来输出2个数字塔,
    0
    01
    012
    0123
    01234
    012345
    0123456
    01234567
    012345678
    0123456789
    0
    01
    012
    0123
    01234
    012345
    0123456
    01234567
    012345678
    0123456789
    如果我想达到如下图的格式,横向的效果要怎么写呢?
    0          0
    01         01
    012        012
    0123       0123
    01234      01234
    012345     012345
    0123456    0123456
    01234567   01234567
    012345678  012345678
    0123456789 0123456789
    ---------------------------------------------------------------------
    回复 1# battab
    @echo off&setlocal enabledelayedexpansion
    set "space=          "
    for /l %%i in (0,1,9) do (
            set/a n=10-%%i,m=%%i-1
            for %%z in (!n!) do set t=!space:~,%%z!
            for /l %%j in (0,1,!m!) do set /p=%%j<nul
            set/p=%%i!t!<nul
            for /l %%j in (0,1,%%i) do set /p=%%j<nul
            echo,
    )
    pause
    ---------------------------------------------------------------------
    @echo off & setlocal enabledelayedexpansion
    for /l %%i in (0 1 9) do set "sp=!sp! "
    for /l %%i in (0 1 9) do (
        set "s="
        for /l %%j in (0 1 %%i) do set "s=!s!%%j"
        set "str=!s!!sp!"
        echo,!str:~,11!!s!
    )
    pause
    ---------------------------------------------------------------------
    继续发另类解:
    @echo off
    %1 cmd /v /c @%0 :|more /t11&pause&exit

    for /f "delims=U" %%a in ('cmd /u /c echo 唉') do set "tab=%%a"
    for /l %%a in (0 1 9) do set str=!str!%%a&echo !str!!tab!!str!
    ---------------------------------------------------------------------
    这个好 mark一下 留着用.
    学习了..
    ---------------------------------------------------------------------
    这样简化
    @echo off&setlocal enabledelayedexpansion
    for /l %%i in (0 1 9) do set "sp=!sp! "
    for /l %%i in (0 1 9) do (
        set "str=!str!%%i"
        echo !str!!sp:~%%i!!str!
    )
    pause
    ---------------------------------------------------------------------
    我也给个自己写的,把第二个for的参数改下,横向的可以打印1,2,3,4,5,6........个数字塔
    @echo off
    for /l %%i in (0,1,9) do (
    for /l %%j in (0,1,1) do (
    for /l %%k in (0,1,10) do (
    if %%k leq %%i (set /p =%%k<nul) else (set /p = <nul)
    )
    )
    echo.
    )
    echo.
    ----------------------------------------------------------------
    参考:http://bathome.net/thread-28624-1-2.html

  • 相关阅读:
    Java入门——(3)面对对象(下)
    Java入门——(8)网络编程
    Java入门——(2)面对对象(上)
    MAC下的Intellij IDEA常用快捷键
    RedHat安装yum+配置国内yum源
    XGBoost算法
    Bagging和Boosting 概念及区别
    关于python的sort和sorted
    sklearn中常用数据预处理方法
    安装Scala
  • 原文地址:https://www.cnblogs.com/mq0036/p/3540433.html
Copyright © 2011-2022 走看看