JAVA在线测试
以考促学,查漏补缺
以考促学,查漏补缺
语言即思维,代码即哲学
以江湖门派为纲,串联站内所有编程笔记。每个门派会收录对应语言的实战心法与案例,持续更新中。
如需补充新的「秘笈」,直接在对应语言目录下创建 Markdown 文件并在此处追加条目即可。
交互式在线答题系统
try-catch-finally 中执行 System.exit(0),finally 会执行吗?Hashtable?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