一.

//小球相撞问题,写得太烦了,原本有点问题就反复加东西,简直不能看
//date:03/11/2019
//code by kohaku
//All rights resvered.
#include<stdio.h>
#include <iostream>
int* seletion_sort(int n, int in[]);
int main()
{
    int n = 0, l = 0, t = 0;
    int* sort;
    int a[100] = { 0 };
    int b[100] = { 0 };                 //工具人数组
    int d[100] = { 0 };
    scanf_s("%d %d %d", &n, &l, &t);
    int min = 0;
    for (int i = 0; i < n; i++){
        scanf_s("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        b[i] = a[i];
    }
    for (int i = 0; i < n; i++) {       //先记录小球初始位置从小到大的顺序,记录到d中
        min = l;                        //d[i]的值代表a[i]的位置
        int h=0;
        for (h = 0; h < n; h++) {
            if (b[h] == -1)continue;
            if (min > b[h]) {
                min = b[h];
                d[i] = h;
            }
        }
        b[d[i]] = -1;
    }
    for (int i = 0; i < n; i++) {
        b[i] = 0;
    }
    for (int i = 0; i < t; i++) {       //不考虑碰撞,直接计算每个球的位置
        for (int c = 0; c < n; c++) {
            if (b[c] == 0) {
                a[c]++;
                if (a[c] == l) {
                    b[c] = 1;
                }
                continue;
            }
            if (b[c] == 1) {
                a[c]--;
                if (a[c] == 0) {
                    b[c] = 0;
                }
                continue;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        b[i] = a[i];
    }
    sort=seletion_sort(n, b);       //排序a中元素
    for (int i = 0; i < n; i++) {   //保留初始位置来给对于的a赋值
        a[d[i]] = sort[i];
    }
    for (int i = 0; i < n; i++) {   //输出顺序
        printf("%d ", a[i]);
    }
}
//这是一个数组选择排序算法
int* seletion_sort(int n, int in[100]) {
    int count = 0;
    int min = in[0];
    int out[1000] = { 0 };
    for (int i = 1; i < n; i++) {
        if (min > in[i])min = in[i];
    }
    int max = min;
    for (int i = n - 1; i >= 0; i--) {
        for (int b = n - 1; b >= 0; b--) {
            if (max <= in[b]) {
                max = in[b];
                count = b;
            }
        }
        out[i] = max;
        in[count] = min - 1;
        max = min;
    }
    return out;
}

二.

//四种函数,没什么参考价值
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include<stdio.h>
#include <iostream>

void put_end();
void put_str(char *str);
int put_ed();
int max(int a, int b);
int main()
{
    put_end();
    char s[100] = { "this is a stupid programme.\n" };
    put_str(s);
    int i = put_ed();
    if (i == -1)printf("failed!");
    int a = 10, b = 29;
    int m = max(a, b);
    printf("%d", m);
}
void put_end() {
    printf("===============================\n");
}
void put_str(char* s) {
    printf("%s", s);
}
int put_ed() {
    if (printf("===============================\n")) {
        return 0;
    }
    else return -1;
}
int max(int a, int b) {
    if (a > b)return a;
    else return b;
}

三.

//冒泡排序,没啥好解释的。
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include <iostream>
void BubbleSort(int a[], int len);
int main()
{
    int len;
    scanf_s("%d", &len);
    int* in;
    in = (int*)malloc(sizeof(int) * len);
    for (int i = 0; i < len; i++) {
        scanf_s("%d", &in[i]);
    }
    BubbleSort(in, len);
    for (int i = 0; i < len; i++) {
        printf("%d ",in[i]);
    }
}
void BubbleSort(int a[], int len) {
    for (int i = 0; i < len; i++) {
        for (int n = 0; n < len-1 - i; n++) {
            if (a[n] > a[n + 1]) {
                a[n] += a[n + 1];
                a[n + 1] = a[n] - a[n + 1];
                a[n] -= a[n + 1];
            }
        }
    }
}

四.

//孪生质数,使用函数实现
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include <iostream>
#include<math.h>
int IsPrime(int value);
int main()
{
    int start = 0, end = 0;
    int t, b;
    scanf_s("%d %d", &start, &end);
    for (; start <= end - 2; start++) {
        t = IsPrime(start);
        b = IsPrime(start + 2);
        if (t == 1 && b == 1) {
            printf("%d %d\n", start, start + 2);
        }
    }
}
int IsPrime(int value) {
    for (int i = 2; i <= sqrt(value); i++) {
        if (value % i == 0)return 0;
    }
    return 1;
}

五(1).

//分别使用递归和循环的方法打印1~10的阶乘
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include <iostream>
int jiechen(int n);
int main()
{
    int n = 1;
    printf("此处为循环:\n");
    for (int i = 1; i <= 10; i++) {
        n *= i;
        printf("%d!=%d\n", i, n);
    }
    printf("此处为递归:\n");
    for (int i = 1; i <= 10; i++) {
        printf("%d!=%d\n", i, jiechen(i));
    }
}
int jiechen(int n) {
    if (n == 1)return 1;
    else return jiechen(n - 1)*n;
}

五(2).

//分别使用递归和循环的方法打印前100个斐波那契序列的数字,递归到后面巨慢
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include <iostream>
double fei(int n);
int main()
{
    printf("循环:\n");
    double out[100] = { 0 };
    out[0] = 1;
    out[1] = 1;
    printf("%.0llf\n%.0llf\n", out[0], out[1]);
    for (int i = 2; i < 100; i++) {
        out[i] = out[i - 1] + out[i - 2];
        printf("%.0llf\n", out[i]);
    }
    printf("递归:\n");
    for (int i = 1; i <= 100; i++) {
        printf("%.0llf\n", fei(i));
    }
}
double fei(int n) {
    if (n == 1 || n == 2)return 1;
    else return fei(n - 1) + fei(n - 2);
}

五(3).

//汉诺塔
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include <iostream>
void move(int n, char a, char b, char c) {
    if (n == 1) {
        printf("move %d from %c to %c.\n", n, a, c);
    }
    else {
        move(n - 1, a, c, b);
        printf("move %d from %c to %c.\n", n, a, c);
        move(n - 1, b, a, c);
    }
}
int main()
{
    int n = 0;
    scanf_s("%d", &n);
    move(n, 'a', 'b', 'c');
}

六.

//不定参数函数
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include<stdarg.h>
#include <iostream>
int sum(int num, ...) {
    va_list argp;                   //定义指针
    int sum = 0;
    va_start(argp, num);            //指针指向第一个元素
    while (num--) {
        sum+=va_arg(argp, int);     //指针向后移动int长度,即下一个元素
    }
    va_end(argp);                   //释放指针
    return sum;
}
int main()
{
    printf("%d", sum(5, 1, 2, 3, 4, 5));
}

七.

//全局变量函数
//date:04/11/2019
//code by kohaku
//All rights resvered.
#include <iostream>
int a = 0;
int b = 0;
int max = 0;
void function(void);
int main(){
    printf("Enter a and b:");
    scanf_s("%d %d", &a, &b);
    function();
    printf("max is %d", max);
}

void function(void) {
    max = (a > b ? a : b);
}


吾辈名为秋月琥珀,今后也请多多关照了