配置数据结构

;  搜狗输入法--自定义短语配置文件

;  自定义短语说明:
;  1、自定义短语支持多行、空格、指定位置。
;  2、每条自定义短语最多支持30000个汉字,总共支持100000条自定义短语。
;  3、自定义短语的格式如下:

;  单行的格式:
;  字符串+英文逗号+数字(指定排序位置)=短语

;  多行的格式:
;  字符串+英文逗号+数字(指定排序位置)=
;  多行短语

;  具体格式可以参考下面的实例。
;  4、最多支持100000行自定义短语。
;  5、自定义短语的用途有:快捷输入手机号、邮箱、诗词、小短文等,大家可以自由发挥。
;  6、时间函数功能。具体定义格式如下:;  字符串+英文逗号+数字(指定排序位置)=#表达式
;  注意:表达式以英文#开头,后面的表达式中的每一个函数的前面都包含有英文$。
;  函数表如下:
;  函数    	含义    	举例
;  $year    	年(4位) 	2006、2008
;  $year_yy	年(2位) 	06、08
;  $month     	月      	12、8、3
;  $month_mm  	月      	12、08、03		//此函数在输入法3.1版之后(含)有效
;  $day     	日      	3、13、22
;  $day_dd	日	       03、13、22	//此函数在输入法3.1版之后(含)有效
;  $weekday 	星期    	0、1、2、5、6
;  $fullhour	时(24小时制)  	2、8、13、23
;  $fullhour_hh	时(24小时制)  	02、08、13、23		//此函数在输入法3.1版之后(含)有效
;  $halfhour	时(12小时制)	2、8、10、11
;  $halfhour_hh	时(12小时制)	02、08、10、11		//此函数在输入法3.1版之后(含)有效
;  $ampm    	AM、PM(英)	AM、PM(大写)
;  $minute  	分      	02、08、15、28
;  $second  	秒      	02、08、15、28
;  $year_cn 	年(中文4位)	二〇〇六
;  $year_yy_cn	年(中文2位)	〇六
;  $month_cn	月(中文)	十二、八、三
;  $day_cn  	日(中文)	三、十三、二十二
;  $weekday_cn 	星期(中文)	日、一、二、五、六
;  $fullhour_cn	时(中文24时制)	二、八、十三、二十三
;  $halfhour_cn	时(中文12时制)	二、八、一、十一
;  $ampm_cn 	上午下午(中文)	上午、下午
;  $minute_cn	分(中文)	零二、零八、十五、二十八
;  $second_cn	秒(中文)	零二、零八、十五、二十八
;  具体你可以参考这个文件最下面的例子,实际体验一下就明白了。
;  你可以用自定义短语来做一个带动态时间的多行回信落款。
;  ss,1=#$year年$month月$day_dd日 $fullhour:$minute:$second

AT,1=
#include<stdio.h>
#include<malloc.h>
typedef struct AVLNode *Position;
typedef Position AVLTree;
typedef struct AVLNode{
    int Data;
    AVLTree Left;
    AVLTree Right;
    int Height;
}AVLNode;
  
int Max(int a,int b){
    if(a>=b)
        return a;
    else
        return b;
}
 
int GetHeight(AVLTree T){
    if (T == NULL)
        return 0;
    else
        return T->Height;
}
 
AVLTree SingleLeftRotation ( AVLTree A ){
    AVLTree B = A->Left;
    A->Left = B->Right;
    B->Right = A;
    A->Height = Max( GetHeight(A->Left), GetHeight(A->Right) ) + 1;
    B->Height = Max( GetHeight(B->Left), A->Height ) + 1;
    return B;
}
 
AVLTree SingleRightRotation (AVLTree A){
    AVLTree B = A->Right;
    A->Right = B->Left;
    B->Left = A;
    A->Height = Max(GetHeight(A->Left),GetHeight(A->Right)) + 1;
    B->Height = Max(GetHeight(B->Right),A->Height) + 1;
    return B;
}
  
AVLTree DoubleLeftRightRotation ( AVLTree A ){
    A->Left = SingleRightRotation(A->Left);
    return SingleLeftRotation(A);
}
 
AVLTree DoubleRightLeftRotation ( AVLTree A ){
    A->Right = SingleLeftRotation(A->Right);
    return SingleRightRotation(A);
}
  
AVLTree Insert( AVLTree T, int X ){
    if ( !T ){
        T = (AVLTree)malloc(sizeof(struct AVLNode));
        T->Data = X;
        T->Height = 0;
        T->Left = T->Right = NULL;
    }
  
    else if ( X < T->Data ) {
        T->Left = Insert( T->Left, X);
        if ( GetHeight(T->Left)-GetHeight(T->Right) == 2 )
            if ( X < T->Left->Data )
               T = SingleLeftRotation(T);  
            else
               T = DoubleLeftRightRotation(T);
    }
      
    else if ( X > T->Data ) {
        T->Right = Insert( T->Right, X );
        if ( GetHeight(T->Left)-GetHeight(T->Right) == -2 )
            if ( X > T->Right->Data )
               T = SingleRightRotation(T);
            else
               T = DoubleRightLeftRotation(T);
    }
    T->Height = Max( GetHeight(T->Left), GetHeight(T->Right) ) + 1;
    return T;
}
 
int PreOrderTraversal(AVLTree T){
    if(T==NULL)
        return 0;
    printf("%d,",T->Data);
    PreOrderTraversal(T->Left);
    PreOrderTraversal(T->Right);
}
 
int main(){
    int i;
    AVLTree T=NULL;
    while(scanf("%d,",&i)!=EOF)
        T=Insert(T,i);
    PreOrderTraversal(T);
    return 0;
}
BH,1=
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Heap {
    int *arr;
    int size;
} Heap;
 
Heap *init() {
    Heap *hh = (Heap *)malloc(sizeof(Heap));
    hh->arr = (int *)malloc(sizeof(int) * 50);
    hh->size = 0;
    return hh;
}
 
// 上滤操作
void percolateUp(Heap *hh, int index) {
    int temp = hh->arr[index];
    int parent = index / 2;
    while (parent > 0 && temp < hh->arr[parent]) {
        hh->arr[index] = hh->arr[parent];
        index = parent;
        parent = index / 2;
    }
    hh->arr[index] = temp;
}
 
// 打印堆
void printHeap(Heap *hh) {
    for (int i = 1; i <= hh->size; i++) {
        printf("%d", hh->arr[i]);
        if (i != hh->size)
            printf(",");
    }
    printf("\n");
}
 
// 下滤构造堆操作
void percolateDown(Heap *hh) {
    int start = hh->size / 2;
    for (int i = start; i > 0; i--) {
        int index = i;
        int temp = hh->arr[index];  // 初始化 temp 为当前节点的值
        while (index * 2 <= hh->size) {
            int child = index * 2;
            if (child != hh->size && hh->arr[child] > hh->arr[child + 1])
                child++;
            if (temp <= hh->arr[child])
                break;
            hh->arr[index] = hh->arr[child];
            index = child;
        }
        hh->arr[index] = temp;
    }
}
 
int main() {
    int n;
    scanf("%d", &n);
    int num;
    Heap *hh = init();  // 用于上滤方法构建堆
    Heap *hh1 = init(); // 用于下滤方法构建堆
 
    for (int i = 0; i < n; i++) {
        scanf("%d", &num);
        if (i != n - 1)
            getchar();
        hh->arr[hh->size + 1] = num;
        hh1->arr[hh1->size + 1] = num;
        hh->size++;
        hh1->size++;
        percolateUp(hh, hh->size);  // 上滤构造堆
    }
 
    percolateDown(hh1);  // 下滤构造堆
 
    printHeap(hh);  // 输出上滤构造的堆
    printHeap(hh1); // 输出下滤构造的堆
 
    return 0;
}
BQ,1=
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
struct Node;
typedef struct Node *position;
typedef struct Node *tree;
typedef struct collection *queue;
struct Node
{
    int x;
    position left, next;
};
 
struct collection
{
    int size;
    tree array[200];
};
queue merge(queue h1, queue h2);
tree combine(tree t1, tree t2);
void printTree(tree T, int k);
 
int main()
{
    char y;
    int x = 0;
    queue H0, H; //用来存储新元素的一个二项队列,且永远只有一个元素
    H0 = malloc(sizeof(struct collection));
    H0->size = 1;
    H = malloc(sizeof(struct collection));
    H->size = 0;
 
    do
    {
        y = getchar();
        if (y != ',')
        {
            x = x * 10 + y - '0';
        }
        else
        {
            tree T = malloc(sizeof(struct Node));
            T->left = T->next = NULL;
            T->x = x;
            H0->array[0] = T;
            H = merge(H, H0);
            H0->array[0] = NULL;
            x = 0;
        }
 
    } while (y != '\n');
 
    int k;
    scanf("%d", &k);
    printTree(H->array[k], k);
 
    return 0;
}
 
queue merge(queue h1, queue h2)
{
    tree t1, t2, carry = NULL;
 
    int i, j;
    h1->size = h1->size + h2->size;
    for (i = 0, j = 1; j <= h1->size; j = j * 2, i++)
    {
        t1 = h1->array[i];
        t2 = h2->array[i];
 
        int judge = !!t1 + 2 * !!t2 + 4 * !!carry;
        if (judge == 2)
        {
            h1->array[i] = t2;
            h2->array[i] = NULL;
        }
        else if (judge == 4)
        {
            h1->array[i] = carry;
            carry = NULL;
        }
        else if (judge == 3)
        {
            carry = combine(t1, t2);
            h1->array[i] = h2->array[i] = NULL;
        }
        else if (judge == 5)
        {
            carry = combine(t1, carry);
            h1->array[i] = NULL;
        }
        else if (judge == 6)
        {
            carry = combine(t2, carry);
            h2->array[i] = NULL;
        }
        else if (judge == 7)
        {
            h1->array[i] = carry;
            carry = combine(t1, t2);
            h2->array[i] = NULL;
        }
    }
    return h1;
}
 
void printTree(tree T, int k)
{
    int num = pow(2, k);
    position p = T;
    if (T == NULL)
    {
        printf("0,");
    }
    else
    {
        for (int i = 1; i <= num; i++)
        {
            printf("%d,", p->x);
            if (p->next == NULL)
            {
                p = p->left;
            }
            else
            {
                p = p->next;
            }
        }
    }
}
 
tree combine(tree t1, tree t2)
{
    if (t2->x < t1->x)
    {
        return combine(t2, t1);
    }
    position p = t1->left;
    if (p == NULL)
    {
        t1->left = t2;
    }
    else
    {
        while (p->next != NULL)
        {
            p = p->next;
        }
        p->next = t2;
    }
    return t1;
}
BS,1=
#include<stdio.h>
#include<string.h>
int isbucket(char a){
    return a=='('||a==')'||a=='['||a==']'||a=='{'||a=='}';
}
int isPair(char c1,char c2){
    if(c1=='('&&c2==')') return 1;
    if(c1=='['&&c2==']') return 1;
    if(c1=='{'&&c2=='}') return 1;
    return 0;
}
int main(){
    char arr[50];
    char stack[50];
    int top=-1;
    scanf("%s",arr);
    int length=strlen(arr);
    for(int i=0;i<length;i++){
        if(isbucket(arr[i])){
            stack[++top]=arr[i];
        }
        if(top>0&&isPair(stack[top-1],stack[top])){
            top=top-2;
        }
    }
    int flag[3]={0};
    int cnt=0;
    while(top>=0){
        if(stack[top]=='('||stack[top]==')'){
            flag[0]=1;
            top--;
            cnt++;
        }
        if(stack[top]=='['||stack[top]==']'){
            flag[1]=2;
            top--;
            cnt++;
        }
        if(stack[top]=='{'||stack[top]=='}'){
            flag[2]=3;
            top--;
            cnt++;
        }
    }
    if(cnt==0) printf("0");
    else{
        for(int i=0;i<3;i++){
            if(flag[i]!=0) printf("%d,",flag[i]);
        }
    }
    return 0;
}
BST,1=
#include <stdio.h>
#include <stdlib.h>
typedef struct Tree
{
    int val;
    int level;
    struct Tree *lchild;
    struct Tree *rchild;
} Tree;
Tree *createNode(int num, int lev)
{
    Tree *node = (Tree *)malloc(sizeof(Tree));
    node->val = num;
    node->lchild = NULL;
    node->rchild = NULL;
    node->level = lev;
    return node;
}
Tree *createTree(Tree *root, int num, int count)
{
    if (root == NULL)
    {
        root = createNode(num, count);
    }
    else
    {
        if (root->val > num)
        {
            root->lchild = createTree(root->lchild, num, ++count);
        }
        else
        {
            root->rchild = createTree(root->rchild, num, ++count);
        }
    }
    return root;
}
void Treeprint(Tree *root, int Level, int *tag)
{
    if (root == NULL)
        return;
    else
    {
        Treeprint(root->lchild, Level, tag);
        if (root->level == Level)
        {
            printf("%d,", root->val);
            *tag = 0;
        }
        Treeprint(root->rchild, Level, tag);
    }
}
int main()
{
    int N;
    int Level;
    int num1;
    scanf("%d", &N);
    scanf("%d,", &num1);
    Tree *root = createNode(num1, 1);
    root->level = 1;
    for (int i = 0; i < N - 1; i++)
    {
        int m;
        scanf("%d,", &m);
        int count = 1;
        createTree(root, m, count);
    }
    scanf("%d", &Level);
    int tag = 1;
    Treeprint(root, Level, &tag);
    if (tag == 1)
    {
        printf("-1");
    }
    return 0;
}
CL,1=
#include<stdio.h>
#include<string.h>
int isCentral(char stack[],int n){
    for(int i=0;i<n;i++){
        if(stack[i]!=stack[n-i]) return 0;
    }
    return 1;
}
int main(){
    char stack[50];
    char str[50];
    int top=-1;
    scanf("%s",str);
    for(int i=0;i<strlen(str);i+=2){
        stack[++top]=str[i];
    }
    if(isCentral(stack,top)==0) printf("No");
    else printf("Yes");
    return 0;
}
HFMJM,1=
#include<stdio.h>
#include<string.h>
typedef struct  
{
       char code;
       char number[6];   
}HuffCode;     
int main()
{
	HuffCode codenumber[10]={
				{'a',"1010"},
				{'b',"00"},
				{'c',"10000"},
				{'d',"1001"},
				{'e',"11"},
				{'f',"10001"},
				{'g',"01"},
				{'h',"1011"}};       
    char input[1024];
    scanf("%s",input);
    int i=0;
    char* p=input;
    while(*p!='\0')
    {
        for(i=0;i<8;i++)
        {
            int length=strlen(codenumber[i].number);
            if(strncmp(p,codenumber[i].number,length)==0)
            {
                printf("%c",codenumber[i].code);
                p+=length;
                break;
            }
        }
    }
    printf("\n");
    return 0;
}



















HTPTM,1=
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct {
    char phone[12];
    int empty;
} element;

typedef struct {
    element* head;
} Hash;

Hash* init() {
    Hash* hh = malloc(sizeof(Hash));
    hh->head = malloc(sizeof(element) * 10);
    for (int i = 0; i < 10; i++) hh->head[i].empty = 0;
    return hh;
}

void insert(Hash* hh, char phone[]) {
    int key = (phone[strlen(phone) - 1] - '0') % 10, count = 0;
    while (hh->head[key].empty) {
        count++;
        key = (phone[strlen(phone) - 1] - '0' + count*count) % 10;
    }
    strcpy(hh->head[key].phone, phone);
    hh->head[key].empty = 1;
}

int main() {
    Hash* hh = init();
    char phone[12], y;
    while (scanf("%11s", phone) != EOF) {
        insert(hh, phone);
        if ((y = getchar()) == '\n' || y == EOF) break;
    }
    for (int i = 0; i < 10; i++) {
        printf("%s", hh->head[i].empty ? hh->head[i].phone : "0");
        if (i < 9) printf(",");
    }
    free(hh->head);
    free(hh);
    return 0;
}
IS,1=
#include <stdio.h>
#include <stdlib.h>

void insertSort(int *arr, int n) {
    for (int i = 1; i < n; i++) {
        int temp = arr[i], j = i;
        while (j > 0 && arr[j - 1] > temp) {
            arr[j] = arr[j - 1];
            j--;
        }
        arr[j] = temp;

        for (int k = 0; k < n; k++)
            printf("%d,", arr[k]);
        printf("\n");
    }
}

int main() {
    int n;
    scanf("%d", &n);
    int *arr = malloc(n * sizeof(int));
    for (int i = 0; i < n; i++) 
        scanf("%d,", &arr[i]);
    insertSort(arr, n);
    free(arr);
    return 0;
}
ITPC,1=
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

typedef struct { char data[100]; int len; } CharStack;
typedef struct { double data[100]; int len; } DoubleStack;

void pushChar(CharStack* s, char val) { s->data[s->len++] = val; }
char popChar(CharStack* s) { return s->data[--(s->len)]; }
char topChar(CharStack* s) { return s->data[s->len - 1]; }
int emptyChar(CharStack* s) { return s->len == 0; }

void pushDouble(DoubleStack* s, double val) { s->data[s->len++] = val; }
double popDouble(DoubleStack* s) { return s->data[--(s->len)]; }
double topDouble(DoubleStack* s) { return s->data[s->len - 1]; }
int emptyDouble(DoubleStack* s) { return s->len == 0; }

int getPriority(char ch) {
    if (ch == '+' || ch == '-') return 0;
    if (ch == '*' || ch == '/') return 1;
    if (ch == '(' || ch == ')') return 2;
    return -1;
}

void toPostfix(char* expression, char* postfix) {
    CharStack ss = {.len = 0};
    int len = 0;
    for (int i = 0; expression[i]; ++i) {
        char ch = expression[i];
        if (isdigit(ch)) {
            postfix[len++] = ch;
            postfix[len++] = ' ';
        } else if (getPriority(ch) != -1) {
            if (ch == ')') {
                while (!emptyChar(&ss) && topChar(&ss) != '(') {
                    postfix[len++] = popChar(&ss);
                    postfix[len++] = ' ';
                }
                popChar(&ss); // Remove '('
            } else {
                while (!emptyChar(&ss) && topChar(&ss) != '(' && getPriority(ch) <= getPriority(topChar(&ss))) {
                    postfix[len++] = popChar(&ss);
                    postfix[len++] = ' ';
                }
                pushChar(&ss, ch);
            }
        }
    }
    while (!emptyChar(&ss)) {
        postfix[len++] = popChar(&ss);
        postfix[len++] = ' ';
    }
    postfix[len] = '\0';
}

double evaluate(char* postfix) {
    DoubleStack ns = {.len = 0};
    for (int i = 0; postfix[i]; ++i) {
        char ch = postfix[i];
        if (isdigit(ch)) {
            pushDouble(&ns, ch - '0');
        } else if (ch != ' ' && !emptyDouble(&ns)) {
            double b = popDouble(&ns);
            double a = popDouble(&ns);
            switch (ch) {
                case '+': pushDouble(&ns, a + b); break;
                case '-': pushDouble(&ns, a - b); break;
                case '*': pushDouble(&ns, a * b); break;
                case '/': pushDouble(&ns, a / b); break;
            }
        }
    }
    return topDouble(&ns);
}

int main() {
    char expression[1024], postfix[1024];
    fgets(expression, sizeof(expression), stdin);
    toPostfix(expression, postfix);
    printf("%.2lf\n%s", evaluate(postfix), postfix);
    return 0;
}
PYQDZ,1=
#include <stdio.h>
#include <stdlib.h>
 
struct arcBox;
typedef struct arcBox *ptrtoArc;
struct arcBox
{
    int from;
    int to;
    ptrtoArc nextInArc;
    ptrtoArc nextOutArc;
};
 
struct vexBox;
typedef struct vexBox *ptrtoVex;
struct vexBox
{
    int name;
    ptrtoArc firstIn;
    ptrtoArc firstOut;
    int beLiked[5];
};
struct graph;
typedef struct graph *Graph;
struct graph
{
    int vexNum;
    int ArcNum;
    ptrtoVex array[5];
};
 
void insertSort(int n, int a[]);
int main()
{
    Graph G;
    G = (struct graph *)malloc(sizeof(struct graph));
    for (int i = 0; i < 5; i++)
    {
        G->array[i] = malloc(sizeof(struct vexBox));
    }
 
    G->vexNum = 5;
 
    for (int i = 0; i < 5; i++)
    {
        G->array[i]->name = i;
        G->array[i]->firstIn = G->array[i]->firstOut = NULL;
    }
 
    //开始建立vex之间的联系
    char y;
    int x1, x2;
    int times = 0;
    while ((y = getchar()) != '\n')
    {
        if (y != ',')
        {
            times++;
            if (times == 1)
            {
                x1 = y - '0';
            }
            if (times == 2)
            {
                x2 = y - '0';
                times = 0;
                ptrtoArc arcNew = malloc(sizeof(struct arcBox));
                arcNew->from = x1;
                arcNew->to = x2;
                // arcNew->nextInArc = arcNew->nextOutArc = NULL;
                //头插
                arcNew->nextOutArc = G->array[x1]->firstOut;
                G->array[x1]->firstOut = arcNew;
                arcNew->nextInArc = G->array[x2]->firstIn;
                G->array[x2]->firstIn = arcNew;
            }
        }
    }
 
    int follow[5];
    int like[5][5];
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            like[i][j] = -1;
        }
    }
 
    for (int i = 0; i < 5; i++)
    {
        int top = -1;
        int n = 0;
        ptrtoArc temp = G->array[i]->firstOut;
        while (temp != NULL)
        {
            follow[++top] = temp->to;
            temp = temp->nextOutArc;
        }
        n = top + 1;
        insertSort(n, follow);
        for (int k = 1; k <= n; k++)
        {
            if (k % 2 == 1)
            {
                like[i][follow[k - 1]] = 1; //i给了[follow[k]] 点了赞
            }
        }
    }
 
    int person;
    scanf("%d", &person);
    int flag = 0;
    for (int i = 0; i < 5; i++)
    {
        if (like[i][person] != -1)
        {
            printf("%d,", i);
            flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("-1");
    }
 
    return 0;
}
 
void insertSort(int n, int a[])
{
    int temp;
    int i, j;
    for (i = 1; i < n; i++)
    {
        temp = a[i];
        for (j = i; j >= 1 && temp < a[j - 1]; j--)
        {
            a[j] = a[j - 1];
        }
        a[j] = temp;
    }
}
QS,1=
#include <stdio.h>
#include <stdlib.h>
#define cutoff 3
void insertSort(int a[], int left, int right);
void Qsort(int a[], int left, int right);
int mid3(int a[], int left, int right);
 
void swap(int *a, int *b);
int main()
{
    int index;
    scanf("%d", &index);
    int a[10] = {49, 38, 65, 97, 76, 13, 27, 50, 2, 8};
 
    int i, j;
    int temp;
    int pivot;
    pivot = a[index];
    temp = a[index];
    a[index] = a[9];
    a[9] = temp;
 
    i = -1;
    j = 9;
 
    for (;;)
    {
        while (a[++i] < pivot)
        {
        }
        while (a[--j] > pivot)
        {
        }
        if (i < j)
        {
            temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
        else
        {
            break;
        }
    }
    temp = a[i];
    a[i] = a[9];
    a[9] = temp;
 
    printf("Qsort(0,9):");
    for (int k = 0; k < 10; k++)
    {
        printf("%d,", a[k]);
    }
    printf("\n");
 
    Qsort(a, 0, i - 1);
    Qsort(a, i + 1, 9);
 
    return 0;
}
 
int mid3(int a[], int left, int right)
{
    int center = (left + right) / 2;
    int temp;
    if (a[left] > a[right])
    {
        temp = a[left];
        a[left] = a[right];
        a[right] = temp;
    }
    if (a[left] > a[center])
    {
        temp = a[left];
        a[left] = a[center];
        a[center] = temp;
    }
    if (a[center] > a[right])
    {
        temp = a[center];
        a[center] = a[right];
        a[right] = temp;
    }
    temp = a[center];
    a[center] = a[right - 1];
    a[right - 1] = temp;
 
    return a[right - 1];
}
 
void Qsort(int a[], int left, int right)
{
    int pivot;
    int i, j;
    int temp;
    if (left + cutoff <= right)
    {
        pivot = mid3(a, left, right);
        i = left;
        j = right - 1;
        for (;;)
        {
            while (a[++i] < pivot)
            {
            }
            while (a[--j] > pivot)
            {
            }
            if (i < j)
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
            else
            {
                break;
            }
        }
        temp = a[i];
        a[i] = a[right - 1];
        a[right - 1] = temp;
 
        printf("Qsort(%d,%d):", left, right);
        for (int k = 0; k < 10; k++)
        {
            printf("%d,", a[k]);
        }
        printf("\n");
 
        Qsort(a, left, i - 1);
        Qsort(a, i + 1, right);
    }
    else
    {
        insertSort(a, left, right);
    }
}
 
void insertSort(int a[], int left, int right)
{
    int temp;
    int i, j;
    for (i = left; i <= right; i++)
    {
        temp = a[i];
        for (j = i; j >= 1 && temp < a[j - 1]; j--)
        {
            a[j] = a[j - 1];
        }
        a[j] = temp;
    }
 
    printf("insert(%d,%d):", left, right - left + 1);
    for (int k = 0; k < 10; k++)
    {
        printf("%d,", a[k]);
    }
    printf("\n");
}
RS,1=
#include <stdio.h>
 

void sort(int a[], int n, int exp);
 
int main()
{
    int x = 0; 
    char y; 
    int a[20]; 
    int top = -1; 
 
   
    while ((y = getchar()) != '\n')
    {
        if (y != ',')
        {
            x = x * 10 + y - '0';
        }
        else
        {
            a[++top] = x; 
            x = 0;
        }
    }
    int n = top + 1; 
    int max = a[0]; 
    for (int i = 1; i < n; i++) 
    {
        if (max < a[i])
        {
            max = a[i];
        }
    }
    int times = 0; 
    int k; 
    scanf("%d", &k);
   
    for (int exp = 1; max / exp > 0; exp *= 10)
    {
        sort(a, n, exp);
        times++;
        if (times == k) 
        {
            for (int j = 0; j < n; j++)
            {
                printf("%d,", a[j]);
            }
        }
    }
 
    return 0;
}
 
void sort(int a[], int n, int exp)
{
    int bucket[10] = {0}; 
    int output[n]; 

    for (int i = 0; i < n; i++)
    {
        int last = (a[i] / exp) % 10;
        bucket[last]++;
    }
 
    for (int i = 1; i < 10; i++)
    {
        bucket[i] += bucket[i - 1];
    }
 
   
    for (int i = n - 1; i >= 0; i--)
    {
        int last = (a[i] / exp) % 10;
        output[bucket[last] - 1] = a[i];
        bucket[last]--;
    }
 
  
    for (int i = 0; i < n; i++)
    {
        a[i] = output[i];
    }
}
SELECTIONS,1=
#include <stdio.h>
#include <stdlib.h>
void selectionSort(int a[], int n);

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d,", &a[i]);
    }
    selectionSort(a, n);

    return 0;
}
void selectionSort(int a[], int n)
{
    int minIndex;
    int i, j;
    int temp;
    for (i = 0; i < n - 1; i++) //注意此处一定是n-1
    {
        minIndex = i;
        for (j = i + 1; j < n; j++)
        {
            if (a[j] < a[minIndex])
            {
                minIndex = j;
            }
        }

        //交换以minIndex 和i为下标的两个元素
        temp = a[minIndex];
        a[minIndex] = a[i];
        a[i] = temp;

        for (int k = 0; k < n; k++)
        {
            printf("%d,", a[k]);
        }
        printf("\n");
    }
}
SHELLS,1=
#include <stdio.h>
#include <stdlib.h>
void printff(int *arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("%d,", arr[i]);
        if (i == n - 1)
            printf("\n");
    }
}
void ShellSort(int *arr, int n)
{
    for (int gap = n / 2; gap >= 1; gap /= 2)
    {
        for (int i = gap; i < n; i++)
        {
            int temp = arr[i];
            int j;
            for (j = i; j >= gap && arr[j - gap]< temp; j -= gap)
            {
                arr[j] = arr[j - gap];
            }
            arr[j] = temp;
        }
        printff(arr, n);
    }
}
int main()
{
    int n;
    scanf("%d", &n);
    int *arr = malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d,", &arr[i]);
    }
    ShellSort(arr, n);
    return 0;
}
SP,1=
#include <stdio.h>
#include <stdlib.h>
#define inf 1e9
struct table;
typedef struct table *Table;

struct table
{
    int x;
    int known;
    int dist;
    int lastVex;
};
void dijkstra(Table T[], int a[8][8]);

int main()
{
    int a[8][8];
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            a[i][j] = inf;
        }
    }

    a[1][2] = 2;
    a[1][4] = 1;
    a[2][4] = 3;
    a[2][5] = 10;
    a[3][1] = 4;
    a[3][6] = 5;
    a[4][3] = 2;
    a[4][5] = 2;
    a[4][6] = 8;
    a[4][7] = 4;
    a[5][7] = 6;
    a[7][6] = 1;
    Table T[8];
    for (int i = 0; i < 8; i++)
    {
        T[i] = malloc(sizeof(struct table));
        T[i]->dist = inf;
        T[i]->known = 0;
        T[i]->lastVex = 0;
    }

    int v, w;
    scanf("%d,%d", &v, &w);

    T[v]->dist = 0;
    dijkstra(T, a);

    int flag = 0;
    if (T[w]->lastVex != 0)
    {
        flag = 1;
        int array[8];
        int i = 0;
        array[i] = w;
        while (T[array[i]]->lastVex != 0)
        {
            array[i + 1] = T[array[i]]->lastVex;
            i++;
        }

        for (; i >= 0; i--)
        {
            printf("%d,", array[i]);
        }
    }
    if (flag == 0)
    {
        printf("-1");
    }

    return 0;
}

void dijkstra(Table T[], int a[8][8])
{
    for (int cnt = 1; cnt <= 7; cnt++)
    {
        int min = inf;
        int v;
        //在未知集合中找一个最小的 v
        for (int i = 1; i <= 7; i++)
        {
            if (T[i]->known == 0)
            {
                if (min > T[i]->dist)
                {
                    min = T[i]->dist;
                    v = i;
                }
            }
        }
        T[v]->known = 1;
        //for every w adjacent to v
        for (int w = 1; w <= 7; w++) //7times
        {
            if (a[v][w] != inf && T[w]->known == 0)
            {
                if (a[v][w] + T[v]->dist < T[w]->dist)
                {
                    T[w]->dist = a[v][w] + T[v]->dist;
                    T[w]->lastVex = v;
                }
            }
        }
    }
}
TBST,1=
#include <stdio.h>
#include <stdlib.h>
typedef struct Tree
{
    int val;
    struct Tree *lchild, *rchild;
} Tree;

Tree *createTree(Tree *root, int num)
{
    if (!root) {
        root = (Tree *)malloc(sizeof(Tree));
        root->val = num;
        root->lchild = root->rchild = NULL;
    } else {
        if (root->val > num)
            root->lchild = createTree(root->lchild, num);
        else
            root->rchild = createTree(root->rchild, num);
    }
    return root;
}

void prePrint(Tree *root)
{
    if (root) {
        printf("%d,", root->val);
        prePrint(root->lchild);
        prePrint(root->rchild);
    }
}

int main()
{
    int num;
    scanf("%d,", &num);
    Tree *root = createTree(NULL, num);
    while (scanf("%d,", &num) != EOF)
        createTree(root, num);
    prePrint(root);
    return 0;
}
TPPX,1=
#include<stdio.h>

int indegree(int a[][11], int size, int n) {
    int num = 0;
    for (int i = 0; i < size; i++) {
        num += a[i][n];
    }
    return num;
}

int main() {
    int a[11][11];
    for (int i = 0; i < 11; i++) {
        for (int j = 0; j < 11; j++) {
            a[i][j] = 0;
        }
    }

    char name[11] = {'S', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'T'};
    a[0][1] = 1;
    a[0][4] = 1;
    a[0][7] = 1;
    a[1][2] = 1;
    a[1][5] = 1;
    a[2][3] = 1;
    a[3][10] = 1;
    a[4][1] = 1;
    a[4][5] = 1;
    a[5][3] = 1;
    a[5][6] = 1;
    a[5][9] = 1;
    a[6][3] = 1;
    a[6][10] = 1;
    a[7][4] = 1;
    a[7][5] = 1;
    a[7][8] = 1;
    a[8][5] = 1;
    a[8][9] = 1;
    a[9][10] = 1;
    a[9][6] = 1;

    char n, m;
    scanf(" %c,%c", &n, &m);
    int numn = -1, numm = -1;
    for (int i = 0; i < 11; i++) {
        if (name[i] == n) numn = i;
        if (name[i] == m) numm = i;
    }

    if (numn == -1 || numm == -1) {
        printf("Invalid input.\n");
        return -1;
    }

    a[numn][numm] = 0;
    a[numm][numn] = 0;

    int queue[11];
    int front = 0, rear = -1;
    int indegrees[11] = {0};

    for (int i = 0; i < 11; i++) {
        for (int j = 0; j < 11; j++) {
            indegrees[j] += a[i][j];
        }
    }

    for (int j = 0; j < 11; j++) {
        if (indegrees[j] == 0) {
            queue[++rear] = j;
        }
    }

    int count = 0;
    while (front <= rear) {
        int x = queue[front++];
        printf("%c,", name[x]);
    

        for (int j = 0; j < 11; j++) {
            if (a[x][j] == 1) {
                a[x][j] = 0;
                if (--indegrees[j] == 0) {
                    queue[++rear] = j;
                }
            }
        }
    }

   

    return 0;
}
WITL,1=
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
    int id;
    struct Node *next;
} Node;
Node *createNode(int a)
{
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode->id = a;
    newNode->next = NULL;
    return newNode;
}
void deletePast(Node *a)
{
    Node *past = a->next;
    a->next = a->next->next;
    printf("%d,", past->id);
    free(past);
}
int main()
{
    int total, cut;
    scanf("%d,%d", &total, &cut);
    Node *head = createNode(1), *past = head;
    for (int i = 2; i <= total; i++)
    {
        past->next = createNode(i);
        past = past->next;
    }
    past->next = head;  // 完成环形链表连接
    Node *current = head;
    for (int remain = total; remain > 1; remain--)
    {
        for (int i = 1; i < cut; i++)  // 跳到第cut个节点
            current = current->next;
        deletePast(current);
        current = current->next;
    }
    printf("%d", current->next->id);  // 输出最后剩下的一个
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值