• 随机生成并排序 C,去同,有序数组合并排序


     1 #include<iostream>
     2 #include<stdlib.h>
     3 #include<time.h>
     4 using namespace std;
     5 
     6 int main(void)
     7 {
     8 
     9         int array[100];
    10         int RANGE_MIN = 0;
    11         int RANGE_MAX = 100;
    12         for (int i = 0; i < 100; i++)
    13         {
    14             int rand100 = (((double) rand() /
    15                 (double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
    16             cin >> array[i];
    17 
    18         }
    19         int temp;
    20 
    21         for (int i = 0; i < 100; i++)
    22             for (int j = 0; j < 99 - i; j++)
    23             {
    24                 if (array[j] > array[j + 1])
    25                 {
    26                     temp = array[j];
    27                     array[j] = array[j + 1];
    28                     array[j + 1] = temp;
    29                 }
    30             }
    31             for (int i = 0; i < 100; i++)
    32                 cout << array[i] << " ";
    33         system("pause");
    34 }
     1 #include<iostream>
     2 #include<stdlib.h>
     3 #include<time.h>
     4 using namespace std;
     5 
     6 int main(void)
     7 {
     8     int *arrayflag = new int;
     9     int array[100];
    10     int RANGE_MIN = 0;
    11     int RANGE_MAX = 100;
    12     for (int i = 0; i < 100; i++)
    13     {
    14         int rand100 = (((double) rand() /
    15             (double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
    16         array[i]=rand100;
    17 
    18     }
    19     int temp;
    20 
    21     for (int i = 0; i < 100; i++)
    22         for (int j = 0; j < 99 - i; j++)
    23         {
    24             if (array[j] > array[j + 1])
    25             {
    26                 temp = array[j];
    27                 array[j] = array[j + 1];
    28                 array[j + 1] = temp;
    29             }
    30         }
    31         //for (int i = 0; i < 100; i++)
    32             //cout << array[i] << " ";
    33         int i = 0, left = 0;
    34         while (i < 100)
    35             arrayflag[i++] = false; //初始化标志数组
    36 
    37         for (i = 0; i < 100; i++)//剔除算法
    38         {
    39             arrayflag[array[i]] = array[i]; //将出现过的数保存到对应的位置
    40 
    41         }
    42         for (i = 0; i < 100; i++) //取出有效数
    43         {
    44             if (arrayflag[i] != false)
    45             {
    46                 array[left++] = arrayflag[i];
    47             }
    48 
    49         }
    50         for (i = 0; i < left-1; i++)
    51             cout << array[i] << " ";
    52         system("pause");
    53 }
     1 #include<iostream>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int a[5] = { 1, 5, 7, 9, 25 }, b[5] = { 1, 27, 26, 38, 99 };
     7     int *c = new int;
     8     int k=4,j=4;
     9     for (int i = 0; i < 10; i++)
    10     {
    11         if (a[j] > b[k])
    12         {
    13             c[i] = a[j];
    14             j--;
    15         }
    16         else
    17         {
    18             c[i] =b[k];
    19             k--;
    20         }
    21     }
    22         for (int i = 0; i < 10; i++)
    23             cout << c[i] << " ";
    24 }
  • 相关阅读:
    HDU4652 Dice
    CF113D Museum / BZOJ3270 博物馆
    SHOI2013 超级跳马
    最基本的卷积与反演
    NOI2014 动物园题解
    SP11414 COT3
    new to do
    linux C++中宏定义的问题:error: unable to find string literal operator ‘operator""fmt’ with ‘const char [4]’, ‘long unsigned int’ arguments
    新装vs2010的问题:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
    windows下删除虚拟串口的方法,以及解决串口使用中,无法变更设备串口号的问题
  • 原文地址:https://www.cnblogs.com/Zblogs/p/3388830.html
Copyright © 2020-2023  润新知