C语言随机生成字符串并进行冒泡排序
											C语言随机生成字符串并进行冒泡排序										
					
	
				
											https://blog.
+
https://blog.										
					
	
	
	
	      
) that you are now a famous director of a tv drama
, thats the way[此贴子已经被作者于2021-10-26 20:15编辑过]
程序代码:#include <stdio.h>
#include <stdlib.h>
 /***********************************************************************
 * open source license: wtfpl                                           *
 * important declaration:                                               *
 * this section is only for fun but it should be taken away from:       *
 * I.   solo young c-player (under 18)                                  *
 * II.  non-experienced c-player (unable to master unpredictable cases) *
 * III. illegal using (out of law)                                      *
 * IV.  <Blank note for future>                                         *
 ***********************************************************************/
#define INC_STR
#ifdef INC_STR
#define V_STR "abcdefghijklmnopqrstuvwxyz"
#endif
#ifdef INC_DIG
#define V_DIG "0123456789"
#endif
#ifdef INC_SPEC
#define V_SPEC "!@#$%^&*-_=+"
#endif
#define swap(x, y)      \
        {               \
            char t;     \
            t = x;      \
            x = y;      \
            y = t;      \
        }
#define FS2B
#ifdef FS2B
#define DIR(_p, _n) _p > _n
#else
#define DIR(_p, _n) _p < _n
#endif
#define STUB 0
#define g_data ((unsigned char *)__TIME__)[idx + _idx] % 26
#define m_data ((unsigned char *)__DATE__)[i] % 10
char* gen_sort(char *s, int len, int _idx)
{
    static int idx;
    int i, j;
    
    //gen
    for (i = 0; i < len; i++, idx -= len)
        s[i] = V_STR[g_data];
    //print
    puts(s);
    //bubble_sort 
    for (i = 0; i < len - 1; i++)
        for (j = 0; j < len - i - 1; j++) 
#define GCC_FEATURE(_expr) (_expr)
            DIR(s[j], s[j + 1]) ? GCC_FEATURE(swap(s[j], s[j + 1])) : STUB;
    //print
    puts(s);
    puts("---------------------");
    return s;
}
int main(int argc, char *argv[])
{
    static char s[10];
    int i;
#ifdef CHK_ASLR
    system("sysctl -n kernel.randomize_va_space");
    printf("addr_i = %p\n", &i);
#endif
    for (i = 0; i < 10; i++)
#define rand_s(_stack) ((_stack) & 0xff)
        gen_sort(s, sizeof(s) - 1,  m_data + rand_s((long int)&i));
    
    return 0;
}[此贴子已经被作者于2021-10-27 10:09编辑过]
