编程语言

JAVA在线测试

以考促学,查漏补缺

◀ 返回

即时生成 AI 考题

点击按钮即可调用本地大模型接口,自动生成新的考试题并追加到页面。

◀ 返回

编程语言

语言即思维,代码即哲学

「编程语言兵器谱」

以江湖门派为纲,串联站内所有编程笔记。每个门派会收录对应语言的实战心法与案例,持续更新中。

🔧 「C 古谱」· 底层乾坤,性能为王

📊 「数据结构」

🐍 「Python 剑诀」· 化繁为简,以柔克刚

  • 计划整理:快速原型、脚本自动化、数据处理常用套路。

☕ 「Java 心经」· 重剑无锋,大巧不工

🟨 「JavaScript 妙法」· 灵动变幻,万象归一

  • 计划整理:可视化组件、前端工程化心得。

🚀 「Go 道术」· 大道至简,并发自然

  • 计划整理:goroutine 调度图谱、微服务脚手架。

🦀 「Rust 玄功」· 内存无患,安全自在

  • 计划整理:所有权系统心法、零成本抽象笔记。

如需补充新的「秘笈」,直接在对应语言目录下创建 Markdown 文件并在此处追加条目即可。

在线答题

交互式在线答题系统

Local Variable 的描述,哪项正确?

A. 局部变量可以使用 public/private 修饰。
B. 局部变量存储在堆(Heap)。
C. 局部变量在定义时必须初始化,否则编译失败。
D. 局部变量具有默认值,例如引用类型默认为 null

try-catch-finally 中执行 System.exit(0)finally 会执行吗?

A. 不会,System.exit(0) 直接终止 JVM,finally 被跳过。
B. 只有 try 未抛异常才执行。
C. 会,finally 总会执行。
D. 取决于 catch 是否捕获 RuntimeException

以下哪一个集合在并发场景下性能优于 Hashtable

A. TreeMap
B. ConcurrentHashMap
C. Hashtable
D. LinkedHashMap

在 Spring AI 中集成阿里云通义千问(Qwen)模型时,应使用哪个官方平台提供的 API Key?

A. 阿里云 RAM AccessKey
B. 阿里云百炼(Model Studio)
C. 阿里云 DashScope
D. 阿里云函数计算(Function Compute)

使用 Spring AI 调用阿里云 DashScope 的 Qwen 模型时,以下哪个 Maven 依赖是正确的?

A. <dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-alibaba-dashscope-spring-boot-starter</artifactId>
</dependency>
B. <dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-alibaba</artifactId>
</dependency>
C. <dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos</artifactId>
</dependency>
D. <dependency>
<groupId>com.aliyun</groupId>
<artifactId>dashscope-sdk</artifactId>
</dependency>

在 Spring Boot 应用中配置 DashScope API Key 时,以下哪种方式最符合安全最佳实践?

A. 直接在 application.yml 中写死:api-key: sk-123456...
B. application.yml 提交到私有 Git 仓库
C. 在 Java 代码中定义常量:private static final String KEY = \"sk-...\";
D. application.yml 中使用 ${DASHSCOPE_API_KEY},并通过环境变量传入

以下关于 Spring AI 与阿里云 Qwen 模型集成的说法,哪一项是错误的?

A. Spring AI 需要 0.8.0 或更高版本才能支持阿里云 DashScope
B. 必须同时提供阿里云 AccessKey ID 和 AccessKey Secret 才能调用 Qwen
C. DashScope 为新用户提供免费调用额度
D. 支持的模型包括 qwen-turbo、qwen-plus 和 qwen-max

题目内容

A. 选项A的内容
B. 选项B的内容
C. 选项C的内容
D. 选项D的内容

在 Spring AI 中集成阿里云通义千问(Qwen)模型时,应使用哪个官方平台提供的 API Key?

A. 阿里云 RAM AccessKey
B. 阿里云百炼(Model Studio)
C. 阿里云 DashScope
D. 阿里云函数计算(Function Compute)

剑法篇

C语言-列表

◀ 返回

线性表

  • 顺序表
  • 链式表

线性表的本质

定义:
	由0个或多个数据元素的集合
	数据元素之间是有顺序的
	数据元素的个数是有限个
	数据元素的类型必须相同
	
专业的定义:
	线性表是具有相同类型的n(n>=0)个数据元素的有限序列
	(a0,a1,a2,..an)
	ai是表项,n是长度
	
性质:
	a0为线性表的第一个元素,只有一个后继
	an为线性表的最后一个元素,只有一个前驱
	除a0和an以外的其他元素ai,既有前驱也有后继.	

线性表的操作

	创建
	销毁
	插入
	删除
	获得表中某个位置的元素
	获得线性表的长度
	清空

线性表的操作对应于我们程序中的一组函数

List *List_Create(void);
void List_Destroy(List *list);
void List_Clear(List *list);
int List_Insert(List *list, ListNode *node, int pos)
ListNode * List_Delete(List *list, int pos)
ListNode * List_Get(List *list, int pos)
int List_Length(List *list)

线性表的顺序存储结构

线性表的顺序存储结构是指用一段地址连续的存储单元依次存储线性表的数据元素 看成C语言的数组,用C语言的一维数组实现顺序存储结构

	#define MAXSIZE 20 //线性表的最大容量
	typedef struct _list {
		char node[MAXSIE]; //存储空间的起始地址是node
		int length; //表示线性表的当前长度
	}List;

获得元素的操作

	char Get(List *list, int pos) {
		char ret = -1;
		
		// 1. 判断list的合法性
		// 2. 判断位置的合法性
		if ( (list!=NULL) &&(0<=pos) && (pos<list->length) )
			// 3. 获得元素	
			ret = list->node[pos];
		return ret;
	}

插入元素的操作

算法:
	1.判断线性表的合法性	
	2.判断插入位置的合法性
	3.把最后一个元素到插入位置的元素依次后移一个位置
	4.将新元素插入
	5.将长度加1
int Insert(List *list, char c, int pos) {
		int ret = (list!=NULL);
		int i = 0;
		
		ret = ret && (list->length <= MAXSIZE);
		ret = ret && (0<=pos);	

		if ( ret ) {
			if ( pos > list->length)
				pos = list->length;
			
			for (i=list->length; i>pos; i--)
				list->node[i] = list->node[i-1]; 
			
			list->node[i] = c;
			list->length++;
		}

		return ret;
	}

删除元素操作

算法:
	1.判断线性表的合法性	
	2.判断删除位置的合法性
	3.将元素取出
	4.将删除位置之后的所有元素都向前移动一个位置
	5.顺序表的长度-1
har Delete(List *list, int pos) {
			char ret = -1;
			int i = 0;
			
			if ( (list!=NULL)&&(0<=pos)&&(pos<list->length) ){
				ret = list->node[pos];
				for (i=pos+1; i<list->length; i++)
					list->node[i-1] = list->node[i];
				list->length--;
			}
		
			return ret;
		}

优点可以快速的获取表中合法位置的元素 缺点插入和删除的时候需要移动大量的元素

剑法篇

C源码加壳解析

◀ 返回

问题描述

字符串被显示为acssi码, 数值被hex加减

源码

转换思路

字符: acssi 转 string 数值: 计算出值

贴代码

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define setnull(x) memset(&(x), 0, sizeof(x))
#define CAL(x, y, z) x + y - z
#define ERR_EXIT(m) \
    do { \
        fprintf(stderr, "[%s][%d]:%s %s \n" ,__FILE__, __LINE__, m, strerror(errno));\
        exit(EXIT_FAILURE); \
        }while(0)


int main( int argc, char **argv){
    int i,j,len,varLen,ilen ;
    char buf[1024];
    char temp[2];
    char var[64],var1[64];
    char ascii[2];
    char hexBuf[1024];
    char fbuf[1024];
    char tobuf[1024];
    int begin = 0, end = 0; 
    char *data;
    char *pstr;
    char *pstr1;
    int retlen;
    char varBuf[20];
    char varRet;
    char srcfile[256],destfile[256];

    setnull(srcfile);
    setnull(destfile);
    sprintf(srcfile,"%s", argv[1]);
    sprintf(destfile,"%s", argv[2]);
    //printf("%s\n",argv[1]);
    //printf("%s\n",srcfile);
    //printf("%s\n",argv[2]);
    //printf("%s\n",destfile);
    //strcpy(hexBuf, argv[1]);
    FILE* fd = fopen(srcfile,"r");
    FILE* fdw = fopen(destfile,"w");
    if(fd){
        while(!feof(fd)){
           memset(fbuf, 0x00, sizeof(fbuf));
           data = fgets(fbuf,sizeof(fbuf)-1,fd);
           if(data){
                memset(tobuf, 0x00, sizeof(tobuf));
                len = strlen(data);
                for (i = 0, j = 0; i < len;){
                   if(!memcmp(data + i,"\\x",2)){
                       memset(ascii, 0x00, 2);
                       memcpy(temp, data + i + 2, 2);
                       //printf("temp: %s\n", temp);
                       hex2ascii(temp, ascii);
                       //printf("ascii: %s\n", ascii);
                       memcpy(tobuf + j, ascii, 1);
                       i += 4;
                       j++;
                       //printf("find \\x string offset %d\n", i); 

                   }else if(!memcmp(data + i,"(0x",3)){
                        memset(var, 0x00, sizeof(var));
                        memset(var1, 0x00, sizeof(var1));
                        memset(varBuf, 0x00, sizeof(varBuf));

                        memcpy(var, data + i, sizeof(var));  
                        //printf("var: %s \n", var);

                        pstr = strchr(var, '(');
                        if ( pstr != NULL)
                        {
                            if( pstr1 = strstr(var, ")")){
                                //printf("find ),\n");
                                varLen = pstr1 - pstr ;
                                //printf("%d\n", varLen);
                                memcpy(var1, var+1,varLen -1);
                                varRet = cal(var1);
                                sprintf(varBuf,"%d",varRet);
                                //printf("%s,%d\n",varBuf,varRet);
                                ilen = strlen(varBuf);
                                memcpy(tobuf + j, varBuf , ilen);
                                j += ilen ;
                                i += varLen + 1;
                            }
                           //else if( pstr1 = strstr(var, ");")){
                           //     printf("find );\n");
                           //     int varLen = pstr1 - pstr ;
                           //     printf("%d\n", varLen);
                           //     memcpy(var1, var+1,varLen -1);
                           //     varRet = cal(var1);
                           //     sprintf(varBuf,"%d;",varRet);
                           //     printf("%s,%d\n",varBuf,varRet);
                           //     int ilen = strlen(varBuf);
                           //     memcpy(tobuf + j, varBuf , ilen + 1);
                           //     j += ilen + 1;
                           //     i += varLen + 1 + 1;
                           // }
                           //else if( pstr1 = strstr(var, ")")){
                           //     printf("find )\n");
                           //     int varLen = pstr1 - pstr ;
                           //     printf("%d\n", varLen);
                           //     memcpy(var1, var+1,varLen -1);
                           //     varRet = cal(var1);
                           //     sprintf(varBuf,"%d",varRet);
                           //     printf("%s,%d\n",varBuf,varRet);
                           //     int ilen = strlen(varBuf);
                           //     memcpy(tobuf + j, varBuf , ilen );
                           //     j += ilen;
                           //     i += varLen + 1;
                           //// }
                        }
                   }else{

                       tobuf[j] = data[i];
                       i++;
                       j++;
                   }

                }
                //printf("%s", data);
                fprintf(fdw,"%s",tobuf);
            }
        }
    }else{
        ERR_EXIT("open file failure");
    }
    fclose(fd);
    //for( i = 0; i < strlen(argv[1]); i++){ 
    //    printf("%c\n", argv[i]);
    //}
    //int ret =  hex2ascii(hexBuf,buf);
    //for( i = 0; i < strlen(buf); i++){ 
    //    printf("%c", buf[i]);
    //}
    //printf("\n");
}

int hex2ascii(char *hex, char *ascii)
{
    int len = strlen(hex), tlen, cnt , i;

    for( i = 0, cnt = 0 ,tlen =0; i < len; i++){
        char c = toupper(hex[i]);

        if(( c >= '0' && c <='9') || ( c >= 'A' && c <= 'F'))
        {
            int  t = ( c >='A') ? c - 'A' + 10 : c - '0';

            if(cnt)
                ascii[tlen++] += t, cnt =0;
            else 
                ascii[tlen] = t << 4, cnt = 1;
                
        }
    }
    return tlen;
}
int cal(char *exprs){

    int x,y,z;
    //printf("%s\n", exprs);
    sscanf(exprs,"%x + %d - %x",&x,&y,&z);
    return CAL(x,y,z); 
}

编译

gcc -o hex2ascii hex2ascii.c