zoukankan      html  css  js  c++  java
  • 13、字符串在指定的地方以及元素个数实行逆置——字符串

    将字符串在指定的地方以及元素个数实行逆置

    将字符串在指定的地方以及元素个数实行逆置

    程序代码如下:

    /*
        2017年3月13日08:57:37
        功能:在指定的地方以及想要逆置元素个数
    */
    #include"stdio.h"
    int *revese(int *, int, int);                  //指向函数的指针,在调用函数中数据改变,将会传给主函数
    int main()
    {
        int a[100] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
        int position;
        int amount;
        printf("请输入开始逆置位置和个数用空格隔开:");                
        scanf("%d %d", &position, &amount);                        
        int *b = reverse(a, position, amount);                                            
        for (int x = 0; x < 10; x++)                //遍历输出字符数组中所有的元素
        {
            printf("%d  ",b[x]);
        }
    }
    int *reverse(int *a, int position, int amount)
    {
        int i = position - 1;
        int j = amount+i -1;
        int t;
        int x = amount/2;
        for (; x > 0; i++, j--)
        {
    
            t = a[j];
            a[j] = a[i];
            a[i] = t;
            x--;
    
        }
        return a;
    
    }
    /*
        总结
        在VC++6.0中显示的结果:
        ————————————————————————
        请输入开始逆置位置和个数用空格隔开:4 6
        2  4  6  18  16  14  12  10  8  20  
        ————————————————————————
    */
  • 相关阅读:
    hdu4734 F(x)
    hdu2089 不要62 两解
    luogu2602 [ZJOI2010]数字计数 两解
    lemon
    UVA1218 完美的服务 Perfect Service
    luogu HNOI2003消防局的设立
    uva10891 game of sum
    uva10635 Prince and Princess
    UVA1394 And Then There Was One
    uva10003切木棍
  • 原文地址:https://www.cnblogs.com/wxt19941024/p/6541080.html
Copyright © 2011-2022 走看看