当前位置: 首页 > news >正文

408代码题汇总

#include<stdio.h> //数组算法题 //10年 void fun1(int r[], int l, int r) { int a = l, j = r; while(a < b) { int temp = r[a]; r[a] = r[b]; r[b] = temp; a++;b--; } } void fun2(int r[], int n, int p) { if(p > 0 && p < n) { fun1(r,0,n-1); fun1(r,0,n-p-1); fun1(r,n-p,n-1); } } //11年 int fun(int A[],int B[],int n){ int i = j = count = 0; while(1){ count++; if(A[i] > B[j]) j++; else i++; if(count == (n - 1) / 2) break; } if(A[i] > B[j]) return B[j]; else return A[i]; } //13年 找主元素 int fun(int A[], int n){ int i, count = 1, temp = A[0]; for(i = 1; i < n; i ++ ) { if(count == 0) temp = A[i]; else { if(A[i] == temp) count ++; else count --; } } count = 0; for(i = 0; i <= n - 1; i ++ ) if(A[i] == temp)count ++; if(count > n / 2)return temp; else return -1; } //16年 void quickSort(int arr[],int l,int r)//left和right的首字母 { if(l>=r) return; int base,temp;int i=l,j=r; base = arr[l]; //取最左边的数为基准数 while(i<j){ while(arr[j]>=base&&i<j)j--;//顺序很重要 while(arr[i]<=base&&i<j) i++; if(i < j) {temp = arr[i];arr[i] = arr[j];arr[j] = temp;} }//基准数归位 arr[l]=arr[i];arr[i]=base; quickSort(arr,l,i-1);//递归左边 quickSort(arr,i+1,r);//递归右边 } int fun(int A[], int n){ quickSort(A, 0, n - 1); int i, s1 = s2 = 0, t = n / 2; for(i = 0; i < n; i ++ ) { if(i < t) s1 += A[i]; else s2 += A[i]; } return s2 - s1; } //18年 int fun(int A[], int n){ int i, *B; B = (int *)malloc(sizeof(int)*(n+1)); //申请辅助空间; memset(B,0,sizeof(int)*(n+1)); //初始化数组 for(i = 0; i < n; i ++ ){ if(A[i] > 0 && A[i] <= n) B[A[i]] = 1; } for(i = 1; i <= n; i ++ ) if(B[i] == 0) break; return i; } //20年---三元组 #define INT_MAX 0x7fffffff int abs(int a){ if(a < 0)return -a; else return a; } int fun(int A[], int a, int B[], int b, int C[], int c) { int i = j = k = 0, D, Dmin = INT_MAX; while(i < a && j < b && k < c && Dmin > 0) { D = abs(A[i] - B[j]) + abs(A[i] - C[k]) + abs(B[j] - C[k]); if(D < Dmin)Dmin = D; if(A[i] <= B[j] && A[i] <= C[k]) i ++; else if(B[j] <= A[i] && B[j] <= C[k]) j ++; else k++; } return Dmin; } //25年 void fun(int A[], int res[],int n){ int i, max, min; max = min = A[n - 1]; for(i = n - 1; i >= 0; i -- ) { if(A[i] > max) max = A[i]; else if(A[i] < min) min = A[i]; if(A[i] > 0) res[i] = A[i] * max; else res[i] = A[i] * min; } } //链表题 //09---倒数k个 typedef struct Node{ int data; struct Node *link; }Node; int fun(Node *head, int k){ Node *temp = head -> link; int length = 0, i; while(temp != Null) { //求表长。 length ++; temp = temp -> link; } if(length < k) return 0; Node *ans = head -> link; for(i = 0; i <= length - k; i ++){ ans = ans -> link; } printf("%d", ans -> data); return 1; } //12年---找公共后缀 typedef struct Node{ int data; struct Node *next; }Node; int len(LNode *head) { int length = 0; while (head -> next != NULL) { length ++ ; head = head -> next; } return length; } Node* fun(Node *str1, Node *str2){ //返回类型为节点。 int m,n; Node *p, *q; m = len(str1); n = len(str2); for(p = str1; m > n; m--) p = p -> next; for(q = str2; m < n; n--) q = q -> next; while(p -> next != NULL && q -> != NULL) { p = p -> next; q = q -> next; } return p -> next; } //15年---删除绝对值相同的点 typedef struct Node{ int data; struct Node *link; }Node; void fun(Node *head, int n){ int *q, m; q = (int *)malloc(sizeof(int)*(n+1)); memset(q,0,sizeof(int)*(n+1)); Node *p = head, *r; while(p -> link != NULL){ int temp = abs(p -> link -> data); if(q[temp] == 0) { q[temp] = 1; p = p -> link; } else { r = p -> link; p -> link = r -> link; free(r); } } free(q); } //19年---链表逆置 + 快慢指针 typedef struct Node{ int data; struct Node *next; }Node; void fun(Node *head){ Node *l, *r, *temp; l = r = h; while(r -> next != NULL) { l = l -> next; r = r -> next; if(r -> next != NULL) r = r -> next; } r = l -> next; //r为后半段的首节点。 l -> next = NULL; while(r -> next != NULL){ //链表后半段逆置 temp = r -> next; r -> next = l -> next; l -> next = r; r = temp; }//最后r指针指向尾巴节点 Node *first = head -> next; while(r != NULL){ Node *temp1 = first -> next; Node *temp2 = r -> next; first -> next = r; r -> next = temp1; first -> next = temp1; r -> next = temp2; } } //树 //14年---求WPL typedef struct node{ int weight; struct *left, *right; }Tree; int func(Tree *tree, int h){ if(tree -> left == NULL && tree -> right == NULL) return (tree -> weight * h); else return (func(tree -> left, h + 1) + func(tree -> right, h + 1)); } int wpl(Tree *tree){ return func(tree, 0); } //17年中缀表达式 typedef struct node{ char data[10]; struct node *left, *right; }Tree; void func(Tree *root, int h){ if(root == NULL) return; if(root -> left == NULL && root -> right == NULL){ printf("%s", root -> data); return; } if(h > 1) printf("("); func(root -> left, h + 1); printf("%s", root -> data); func(root -> right, h + 1); if(h > 1) printf(")"); } //22年---二叉搜索树的判定---太难了。 //图 //21年---EL路径 int func(MGraph G){ int i, j, degree, count; for(i = 0; i < G.numVertices; i ++ ){ degree = 0; for(j = 0; j < G.numVertices; j ++ ){ if(G.Edge[i][j] == 1) degree ++; } if(degree % 2 == 1) count ++; } if(count == 0 || count == 2) return 1; else return 0; } //23年 int func(MGraph G){ int i, j, in, out, count; for(i = 0; i < G.numVertices; i ++){ in = out = 0; for(j = 0; j < G.numVertices; j ++){ if(G.Edge[i][j] == 1) out ++; if(G.Edge[j][i] == 1) in ++; } if(out > in) { printf("%s", G.VerticesLit[i]); count ++; } } return count; } //24年---拓扑排序---太难了。 int func(MGraph G){ int *degree, i, j, n = G.numVertices; degree = (int*)malloc(sizeof(int)*n); for(i = 0; i < n; i ++) for(j = 0; j < n; j ++) degree[i] += G.Edge[i][j]; }
http://www.jsqmd.com/news/80027/

相关文章:

  • GPT-OSS开源大模型深度解析:技术架构、性能表现与产业价值
  • 天津 5 家正规大平层设计工作室,竟藏着这些不为人知的亮点!
  • 升级指引手册:平滑过渡到最新版本的最佳实践
  • 空洞骑士模组管理革命:Scarab工具完全解析
  • Qwen3-VL系列震撼登场:多模态大模型开启视觉智能新纪元
  • OpenAI Whisper:重新定义语音识别技术的多语言AI模型全解析
  • 腾讯发布混元3D-Omni框架:多模态控制技术重塑3D资产生成范式
  • 腾讯混元开源四款轻量级模型:端侧AI落地的全新突破
  • GLM-4-9B模型重大更新:技术报告迭代与性能优化全面解析
  • 全能多模态新纪元:Lumina-DiMOO凭四大技术突破重构AI能力边界
  • 英博云推出Qwen3-VL超大规模多模态模型服务,助力企业视觉智能升级
  • StepFun-Formalizer:大语言模型知识推理融合的自动形式化突破
  • 突破电解液研发瓶颈:字节跳动Bamboo-mixer框架实现预测生成一体化材料设计革命
  • 人工智能技术突破:引领未来产业变革的核心驱动力
  • 人工智能大模型发展现状与未来趋势:技术突破与产业变革的双重驱动
  • 2025 AI芯片与模型技术爆发:从云端到终端的全栈革新
  • 快手开源AutoThink大模型:应对AI“过度思考”难题,动态推理技术引领行业新方向
  • 低显存运行大模型:Quanto+Diffusers优化Transformer扩散模型实践指南
  • 270M参数引爆边缘智能:Gemma 3轻量化模型如何改写AI部署规则
  • 15、Linux 命令行文档获取与使用指南
  • IBM Granite 4.0:混合架构革新引领企业级AI效率革命
  • 16、Linux 文件管理全解析
  • 技术领域重大突破:新型人工智能模型引领行业变革
  • 英伟达发布OpenReasoning-Nemotron推理套件:轻量化模型改写AI本地部署格局
  • Tar系列模型突破性进展:文本对齐表征技术引领跨模态AI新纪元
  • SGLang参数调优实战:打造企业级LLM推理服务的性能引擎
  • 17、Linux 文件管理全解析
  • 开源代码编辑新纪元:Continue推出Instinct模型,重新定义开发者工作流
  • 通义大模型矩阵震撼发布:多模态AI技术引领千行百业智能化革命
  • Qwen3-Reranker-8B震撼发布:多语言文本重排序新纪元,80亿参数重构检索范式