• 记录4--一个有趣的逆序算法


     1 #include <stdio.h>
     2 
     3 void InvertStore(char A[])
     4 //字符串逆序存储的递归算法。
     5 {
     6 char ch;
     7 static int i = 0;//需要使用静态变量
     8 ch=getchar();
     9 if (ch!= '
    ') //规定'
    '是字符串输入结束标志
    10 {
    11 InvertStore(A);
    12 A[i++] = ch;//字符串逆序存储
    13 }
    14 A[i] = ''; //字符串结尾标记
    15 }
    View
    #include <stdio.h>
    
    void InvertStore(char A[])
    //字符串逆序存储的递归算法。
    {
    char ch;
    static int i = 0;//需要使用静态变量
    ch=getchar();
    if (ch!= '
    ') //规定'
    '是字符串输入结束标志
    {
    InvertStore(A);
    A[i++] = ch;//字符串逆序存储
    }
    A[i] = ''; //字符串结尾标记
    }
    Code

    /* getchar()是使用键盘缓冲区的函数,只有缓冲区满了或者敲了回车,这个函数才能执行
    char c;
    while ( (c = getchar()) != EOF )
        {
           putchar(c);
        }
    /*
    理解的顺序是:声明完c的类型之后来到第2行 >> getchar() >> 等待输入 >>
    用户输入一串字符(如 ef,按下回车) >> c被赋值为'e' >>
    'e' != EOF >> putchar(c)输出一个字符'e' >> c被赋值为'f' >>
    'f' != EOF >> putchar(c)输出一个字符'f' >> c被赋值为' ' >>
    ' ' != EOF >> putchar(c)输出一个字符' '

  • 相关阅读:
    【bzoj4066】 简单题
    【bzoj1941】 Sdoi2010—Hide and Seek
    【bzoj2648】 SJY摆棋子
    【poj2154】 Color
    【poj2409】 Let it Bead
    【codevs1106】 篝火晚会
    【poj3270】 Cow Sorting
    【bzoj1004】 HNOI2008—Cards
    【bzoj3143】 Hnoi2013—游走
    【codeforces 749E】 Inversions After Shuffle
  • 原文地址:https://www.cnblogs.com/zhuimingzhenbai/p/12158420.html
Copyright © 2020-2023  润新知