Skip navigation.

青春的岁月

——只因那胸中燃烧的理想

STICKY POST

加入了一个计数器

欢迎你!你是第Free Hit Counter来访者

亲爱的朋友呀,当我静听着海涛时,我有好几次在暮色深沉的黄昏里,在这个海岸上,感得你的伟大思想的沉默了。 --泰戈尔诗

这一段时间

#include<stdio.h>
#include<stdlib.h>

typedef struct node{
int num;
struct node* nex_ptr;
struct node* pre_ptr;
}NODE;

typedef struct list{
char pare;
int charnum;
int length;
NODE head,tail;
}LIST;

int initlist(LIST* list){
list->head.pre_ptr=NULL;list->head.nex_ptr=NULL;
list->tail.nex_ptr=NULL;
list->charnum=0;
list->length=0;
return 1;
}

int addnum(LIST* list,int num){
NODE* ptr=malloc(sizeof(NODE));
ptr->num=num;
if(list->head.nex_ptr==NULL){
list->head.nex_ptr=ptr;list->tail.pre_ptr=ptr;
ptr->pre_ptr=&(list->head);ptr->nex_ptr=&(list->tail);
}else{
ptr->pre_ptr=list->tail.pre_ptr;ptr->nex_ptr=&(list->tail);
list->tail.pre_ptr->nex_ptr=ptr;list->tail.pre_ptr=ptr;
}
return 1;
}

int createlist(LIST* list){
char c;
int cal=0,num=0;
int charnum=0,length=0;
scanf("%c",&c);
list->pare=c;
while(scanf("%c",&c) && c != '#'){
if( c != ',' ){
list->charnum++;
num *= 10;
num += c-'0' ;
}else{
addnum(list,num);
list->length++;
num = 0;
}

}
return 1;
}

int addlist(LIST* list1,LIST* list2,LIST* list3){
int num=0,flag=0;
NODE* ptr1=list1->tail.pre_ptr;
NODE* ptr2=list2->tail.pre_ptr;
NODE* ptr3=list3->tail.pre_ptr;
while( ptr2->pre_ptr != NULL ){
if( ptr1->num + ptr2->num + flag >= 10000 ){
num = ptr1->num + ptr2->num + flag -10000;
addnum(list3,num);
flag=1;
}else{
num = ptr1->num + ptr2->num + flag;
addnum(list3,num);
flag=0;
}
ptr1=ptr1->pre_ptr;
ptr2=ptr2->pre_ptr;
num=0;
}

while( ptr1->pre_ptr != NULL ){
if( ptr1->num + flag >= 10000 ){
num = ptr1->num + flag - 10000;
addnum(list3,num);
flag=1;
}else{
num = ptr1->num + flag;
addnum(list3,num);
flag=0;
}
ptr1=ptr1->pre_ptr;
num=0;
}

if(flag){
addnum(list3,flag);
}
return 1;
}

int sublist(LIST* list1,LIST* list2,LIST* list3){
int num,flag=0;
NODE* ptr1=list1->tail.pre_ptr;
NODE* ptr2=list2->tail.pre_ptr;
NODE* ptr3=list3->tail.pre_ptr;
while( ptr2->pre_ptr != NULL ){
if( ptr1->num + flag < ptr2->num ){
num=10000 + ptr1->num + flag - ptr2->num;
addnum(list3,num);
flag=-1;
}else{
num = ptr1->num + flag - ptr2->num;
addnum(list3,num);
flag=0;
}

ptr1=ptr1->pre_ptr;
ptr2=ptr2->pre_ptr;
num=0;
}

while( ptr1->pre_ptr != NULL ){
if( ptr1->num + flag < 0 ){
num=10000 + ptr1->num + flag;
addnum(list3,num);
flag = -1;
}else{
num=ptr1->num + flag;
addnum(list3,num);
flag = 0;
}
ptr1=ptr1->pre_ptr;
num=0;
}

return 1;
}

int bigthen(LIST* list1,LIST* list2){
NODE *ptr1=list1->head.nex_ptr,*ptr2=list2->head.nex_ptr;
if( list1->charnum > list2->charnum ) return 1;
if( list1->charnum == list2->charnum ){
while( ptr1->nex_ptr != NULL ){
if( ptr1->num > ptr2->num ) return 1;
if( ptr1->num < ptr2->num ) return 0;
ptr1=ptr1->nex_ptr;ptr2=ptr2->nex_ptr;
}
}
return 0;
}

int calist(LIST* list1,LIST* list2,LIST* list3){
int flag=bigthen(list1,list2);
if( flag ){
if( list1->pare == '+' && list2->pare == '+' )
{ sublist(list1,list2,list3);list3->pare='+';}
else if( list1->pare == '+' && list2->pare == '-' )
{ addlist(list1,list2,list3);list3->pare='+';}
else if( list1->pare == '-' && list2->pare == '+' )
{ addlist(list1,list2,list3);list3->pare='-';}
else if( list1->pare == '-' && list2->pare == '-' )
{ sublist(list1,list2,list3);list3->pare = '-';}
}
else{
calist(list2,list1,list3);
if( list3->pare == '+' )
list3->pare = '-';
elselist3->pare = '+';
}
return 1;
}

int trav_list_bak(LIST* list){
NODE* ptr=list->tail.pre_ptr;
printf("%c",list->pare);
while(ptr->pre_ptr != NULL){
if( ptr->num >= 1000 )
printf("%d,",ptr->num);
else if( ptr->num >= 100 )
printf("0%d,",ptr->num);
else if( ptr->num >= 10 )
printf("00%d,",ptr->num);
else if( ptr->num >=0 )
printf("000%d,",ptr->num);
ptr=ptr->pre_ptr;
}
return 1;
}

int main(){
LIST list1,list2,list3;
initlist(&list1);initlist(&list2);initlist(&list3);
int i=1;
while(i){
printf("put num as formate +/-xxxx,xxxx,....,#+/-xxxx,xxxx,#\n");
createlist(&list1);
createlist(&list2);
printf("--------------------\n");
calist(&list1,&list2,&list3);
trav_list_bak(&list3);
printf("\ndo your want to continue,1 for yes,0 for no ?\n");
scanf("%d", &i);
printf("\n");
}
return 0;
}

#include<stdio.h>
#include<stdlib.h>

typedef union value{
char alg;
int num;
}VAL;

typedef struct node{
int type;
VAL content;
struct node* pre_ptr;
struct node* nex_ptr;
}NODE;

typedef struct list{
int length;
NODE head,tail;
}LIST;

int initlist(LIST* list){
list->head.type=0;list->head.content.alg='(';
list->tail.type=0;list->tail.content.alg=')';
list->head.pre_ptr=NULL;
list->head.nex_ptr=NULL;
list->tail.nex_ptr=NULL;
list->length=0;
return 1;
}

int creatnode(LIST* list,NODE* val){
if( list->head.nex_ptr==NULL ){
val->pre_ptr=&(list->head);val->nex_ptr=&(list->tail);
list->head.nex_ptr=val;list->tail.pre_ptr=val;
}else{
val->pre_ptr=list->tail.pre_ptr;val->nex_ptr=&(list->tail);
list->tail.pre_ptr->nex_ptr=val;list->tail.pre_ptr=val;
}
list->length++;
return 1;
}


int createlist(LIST* list){
int flag=1;
char c;
NODE* ptr;
while(scanf("%c",&c) && c != '='){
if( c=='+' || c=='-' || c=='x' || c=='/' || c=='(' || c==')' ){
ptr=malloc(sizeof(NODE));
ptr->type=0;ptr->content.alg=c;
creatnode(list,ptr);
flag=1;
}else if( c>=48 && c<=57 ){
int bit=c-48;
if(flag){
ptr=malloc(sizeof(NODE));
ptr->type=1;ptr->content.num=bit;
creatnode(list,ptr);
flag=0;
}else{
list->tail.pre_ptr->content.num *= 10;
list->tail.pre_ptr->content.num += bit;
flag=0;
}
}
}
return 1;
}

int calpare(NODE* node){
int num;
NODE *ptr,*ptr_bak=node;
node=node->nex_ptr;

//printf("num:%d",node->content.num);
while( !( node->type == 0 && node->content.alg == ')' ) ){
if( node->type == 0 && (node->content.alg == 'x'||node->content.alg == '/') ){
if(node->content.alg == 'x'){
num=(node->pre_ptr->content.num) * (node->nex_ptr->content.num);
}
if(node->content.alg == '/'){
if( node->nex_ptr->content.num==0 ){printf("div can not be zero !");return 0;}
num=(node->pre_ptr->content.num) / (node->nex_ptr->content.num);
}
ptr=malloc(sizeof(NODE));
ptr->type=1;ptr->content.num=num;

ptr->pre_ptr=node->pre_ptr->pre_ptr;ptr->nex_ptr=node->nex_ptr->nex_ptr;
node->pre_ptr->pre_ptr->nex_ptr=ptr;node->nex_ptr->nex_ptr->pre_ptr=ptr;

free(node->pre_ptr);free(node->nex_ptr);
free(node);node=ptr;
}
node=node->nex_ptr;
}


node=ptr_bak->nex_ptr;
while( !( node->type == 0 && node->content.alg == ')' ) ){
if( node->type == 0 && (node->content.alg == '+'||node->content.alg == '-') ){
if(node->content.alg == '+'){
num=(node->pre_ptr->content.num) + (node->nex_ptr->content.num);
}
if(node->content.alg == '-'){
num=(node->pre_ptr->content.num) - (node->nex_ptr->content.num);
}
ptr=malloc(sizeof(NODE));
ptr->type=1;ptr->content.num=num;

ptr->pre_ptr=node->pre_ptr->pre_ptr;ptr->nex_ptr=node->nex_ptr->nex_ptr;
node->pre_ptr->pre_ptr->nex_ptr=ptr;node->nex_ptr->nex_ptr->pre_ptr=ptr;

free(node->pre_ptr);free(node->nex_ptr);
free(node);node=ptr;
}
node=node->nex_ptr;
}


return 1;
}

int rmpare(LIST* list){
NODE *ptr,*tmp;
ptr=&(list->tail);
while(ptr->pre_ptr!=NULL){
if( ptr->type == 0 && ptr->content.alg == '(' ) {calpare(ptr);}
ptr=ptr->pre_ptr;
}

ptr=list->head.nex_ptr;
while( ptr->nex_ptr != NULL ){
if( ptr->type==0 && ( ptr->content.alg=='(' || ptr->content.alg==')' ) ){
ptr->pre_ptr->nex_ptr=ptr->nex_ptr;ptr->nex_ptr->pre_ptr=ptr->pre_ptr;
tmp=ptr;ptr=ptr->nex_ptr;
free(tmp);
continue;
}
ptr=ptr->nex_ptr;
}
calpare(&(list->head));
printf("the result is %d\n",list->head.nex_ptr->content.num);
}

int travel_list(LIST* list){
NODE* ptr=list->head.nex_ptr;
printf("\n");
while(ptr->nex_ptr != NULL){
if(ptr->type){
printf("%d,%d",ptr->type,ptr->content.num);
}else{
printf("%d,%c",ptr->type,ptr->content.alg);
}
ptr=ptr->nex_ptr;
printf("\n");
}
printf("\n");
return 1;
}


int main(){
LIST list;
initlist(&list);
createlist(&list);
NODE* ptr;
ptr=&(list.tail);

rmpare(&list);
return 0;
}


#include<stdio.h>
#include<stdlib.h>

typedef union numorchar{
int num;
char pare;
}NUMORCHAR;

typedef struct node{
int type;
NUMORCHAR content;
struct node* nex_ptr;
}NODE;

typedef struct stack{
NODE head;
NODE* tail;
}STACK;

int initstack(STACK* stack){
stack->head.type=0;
stack->head.content.pare='#';
stack->head.nex_ptr=NULL;
stack->tail=&(stack->head);
return 1;
}

int pushchar(STACK* stack,char c){
NODE* ptr=malloc(sizeof(NODE));
ptr->content.pare=c;
switch (c)
{
case '#'p:tr->type=0;
break;
case '+'p:tr->type=2;
break;
case '-'p:tr->type=2;
break;
case '*'p:tr->type=4;
break;
case '/'p:tr->type=4;
break;
case '('p:tr->type=8;
break;
case ')'p:tr->type=1;
break;
}
stack->tail->nex_ptr=ptr;
stack->tail=ptr;stack->tail->nex_ptr=NULL;
return 1;
}


int pushchar_in(STACK* stack,char c){
NODE* ptr=malloc(sizeof(NODE));
ptr->content.pare=c;
switch (c)
{
case '#'p:tr->type=0;
break;
case '+'p:tr->type=3;
break;
case '-'p:tr->type=3;
break;
case '*'p:tr->type=5;
break;
case '/'p:tr->type=5;
break;
case '('p:tr->type=1;
break;
case ')'p:tr->type=8;
break;
}
stack->tail->nex_ptr=ptr;
stack->tail=ptr;stack->tail->nex_ptr=NULL;
return 1;
}

int pushint(STACK* stack,int n){
NODE* ptr=malloc(sizeof(NODE));
ptr->type=9;ptr->content.num=n;
stack->tail->nex_ptr=ptr;
stack->tail=ptr;stack->tail->nex_ptr=NULL;
return 1;
}

char popchar(STACK* stack){
NODE* ptr=&(stack->head);
while( ptr->nex_ptr != stack->tail ){ ptr=ptr->nex_ptr ;}
stack->tail=ptr;ptr=ptr->nex_ptr;
char c=ptr->content.pare;
free(ptr);stack->tail->nex_ptr=NULL;
return c;
}

int popint(STACK* stack){
NODE* ptr=&(stack->head);
while( ptr->nex_ptr != stack->tail ){ ptr=ptr->nex_ptr ;}
stack->tail=ptr;ptr=ptr->nex_ptr;
int n=ptr->content.num;
free(ptr);stack->tail->nex_ptr=NULL;
return n;
}

int createstack( STACK* stack){
char c;
int num,flag=1;
NODE* ptr;
while( scanf("%c",&c) ){
if( c=='+' || c=='-' || c=='*' || c=='/' || c=='(' || c==')' || c=='#' || c=='=' ){
if(!flag) pushint(stack,num);
if(c == '=') break;
pushchar(stack,c);flag=1;
}else if( c>=48 && c<=57 ){
int bit=c-48;
if( flag ){
num=bit;
}else{
num *= 10;
num +=bit;
}
flag=0;
}
}
return 1;
}

int fixpost(STACK* stack1,STACK* stack2,STACK* stack3){
NODE* ptr=stack1->head.nex_ptr;
while(1){
if( ptr->type == 9 ){
pushint(stack2,ptr->content.num);
}else{
if( ptr->type > stack3->tail->type){
pushchar_in(stack3,ptr->content.pare);
}else{
while( ptr->type <= stack3->tail->type ){
pushchar(stack2,popchar(stack3));
}
pushchar_in(stack3,ptr->content.pare);
}
}
if( ptr->nex_ptr == NULL ){
while( stack3->tail->content.pare != '#' ){
pushchar(stack2,popchar(stack3));
}
break;
}
ptr=ptr->nex_ptr;
}
return 1;
}

int cal(STACK* stack1,STACK* stack2){
NODE* ptr=stack1->head.nex_ptr;
int num,num1,num2;
while(1){
if(ptr->type == 9){
pushint(stack2,ptr->content.num);
}else{
switch (ptr->content.pare)
{
case '+':num1=popint(stack2);num2=popint(stack2);
num=num2+num1;pushint(stack2,num);break;
case '-':num1=popint(stack2);num2=popint(stack2);
num=num2-num1;pushint(stack2,num);break;
case '*':num1=popint(stack2);num2=popint(stack2);
num=num2*num1;pushint(stack2,num);break;
case '/':num1=popint(stack2);num2=popint(stack2);
num=num2/num1;pushint(stack2,num);break;
}
}
if(ptr->nex_ptr == NULL){
printf("the result is %d\n",stack2->head.nex_ptr->content.num);
break;
}
ptr=ptr->nex_ptr;
}
return 1;
}

int trav_stack(STACK* stack){
NODE* ptr=&(stack->head);
while(1){
if( ptr->type == 9 ){
printf("%d,%d\n",ptr->type,ptr->content.num);
}else{
printf("%d,%c\n",ptr->type,ptr->content.pare);
}
if( ptr->nex_ptr == NULL ) break;
ptr=ptr->nex_ptr;
}
return 1;
}

int main(){
int an=1;
STACK stack1,stack2,stack3,stack4;
initstack(&stack1);initstack(&stack2);initstack(&stack3);initstack(&stack4);
createstack(&stack1);
printf("----------------------\n");
fixpost(&stack1,&stack2,&stack3);
cal(&stack2,&stack4);
return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

typedef struct customer{
int arrive_time;
int need_service_time;
int waiting_time;
struct customer* nex_ptr;
}CUSTOMER;

//--------------------------------------------

typedef struct customer_queue{
int teller_service_customers;
int teller_service_time;
int teller_waiting_list_time;
int teller_waiting_time_all;
int teller_free_time;
CUSTOMER head;
CUSTOMER tail;
}CUSTOMER_QUEUE;

int init_customer_queue(CUSTOMER_QUEUE* queue){
queue->teller_service_time=0;
queue->teller_waiting_list_time=0;
queue->teller_service_customers=0;
queue->teller_waiting_time_all=0;
queue->head.nex_ptr=&(queue->tail);
queue->head.arrive_time=0;queue->head.waiting_time=0;
queue->tail.arrive_time=1001;queue->tail.waiting_time=0;
queue->tail.nex_ptr=NULL;
return 1;
}

int customer_queue_in(CUSTOMER_QUEUE* queue,CUSTOMER* customer){
if(queue->head.nex_ptr == &(queue->tail)){
queue->head.nex_ptr=customer;
customer->nex_ptr=&(queue->tail);
}else{
customer->nex_ptr=queue->head.nex_ptr;
queue->head.nex_ptr=customer;
}
return 1;
}

int customer_queue_out(CUSTOMER_QUEUE* queue){
CUSTOMER* ptr=&(queue->head);
if( ptr->nex_ptr == &(queue->tail)){
return 0;
}else{
while(ptr->nex_ptr->nex_ptr != &(queue->tail) ) ptr=ptr->nex_ptr;
ptr->nex_ptr=&(queue->tail);
}
return 1;
}

CUSTOMER_QUEUE* least_waiting_time(CUSTOMER_QUEUE* queue1,CUSTOMER_QUEUE* queue2,
CUSTOMER_QUEUE* queue3,CUSTOMER_QUEUE* queue4){
CUSTOMER_QUEUE* ptr=queue1;
if( ptr->teller_waiting_list_time > queue2->teller_waiting_list_time ) ptr=queue2;
if( ptr->teller_waiting_list_time > queue3->teller_waiting_list_time ) ptr=queue3;
if( ptr->teller_waiting_list_time > queue4->teller_waiting_list_time ) ptr=queue4;
return ptr;
}

int max_waiting_list_time(CUSTOMER_QUEUE* queue1,CUSTOMER_QUEUE* queue2,
CUSTOMER_QUEUE* queue3,CUSTOMER_QUEUE* queue4){
int waiting_list_time=queue1->teller_waiting_list_time;
if( queue2->teller_waiting_list_time > waiting_list_time ) waiting_list_time=queue2->teller_waiting_list_time;
if( queue3->teller_waiting_list_time > waiting_list_time ) waiting_list_time=queue3->teller_waiting_list_time;
if( queue4->teller_waiting_list_time > waiting_list_time ) waiting_list_time=queue4->teller_waiting_list_time;
return waiting_list_time;
}
//--------------------------------------------

typedef struct customer_list{
CUSTOMER head;
CUSTOMER tail;
}CUSTOMER_LIST;

int create_customer_list(CUSTOMER_LIST* customer_list){
int arrivetime,needservicetime;
srand((unsigned)time(NULL));
CUSTOMER *ptr1,*ptr2;
customer_list->head.nex_ptr=&(customer_list->tail);customer_list->tail.nex_ptr=NULL;
customer_list->head.arrive_time=0;customer_list->tail.arrive_time=1001;
int i=1;
while(i <= 100){
arrivetime=rand()%100+1;needservicetime=(rand()%3+1)*5;
ptr1=malloc(sizeof(CUSTOMER));
ptr1->arrive_time=arrivetime;ptr1->need_service_time=needservicetime;
ptr1->waiting_time=0;
ptr2=&(customer_list->head);
while(ptr1->arrive_time > ptr2->nex_ptr->arrive_time)ptr2=ptr2->nex_ptr;
ptr1->nex_ptr=ptr2->nex_ptr;ptr2->nex_ptr=ptr1;
i++;
}
return 1;
}

CUSTOMER* pop_customer_list(CUSTOMER_LIST* customer_list){
CUSTOMER* ptr;
if(customer_list->head.nex_ptr == &(customer_list->tail)){
return &(customer_list->tail);
}else{
ptr=customer_list->head.nex_ptr;
customer_list->head.nex_ptr=ptr->nex_ptr;
return ptr;
}
}

//--------------------------------------------

int out_queue(CUSTOMER_QUEUE* queue1,int timeout){
int i=10;
CUSTOMER* ptr;
if( queue1->teller_waiting_list_time == timeout ){
queue1->teller_waiting_list_time = 0;
queue1->teller_service_time += timeout;
while( customer_queue_out(queue1) ) ;
}else if( queue1->teller_waiting_list_time < timeout ){
queue1->teller_service_time += queue1->teller_waiting_list_time;
queue1->teller_waiting_list_time = 0;
while( customer_queue_out(queue1) ) ;
}else if( queue1->teller_waiting_list_time > timeout ){
queue1->teller_service_time += timeout;
queue1->teller_waiting_list_time -= timeout;
while(1){
ptr=&(queue1->head);
while(ptr->nex_ptr != &(queue1->tail) ) ptr=ptr->nex_ptr;
if( timeout >= ptr->need_service_time ){
timeout=timeout - ptr->need_service_time;
customer_queue_out(queue1);
}else{
ptr->need_service_time -= timeout; break;
}

}
}

return 1;
}

int out(CUSTOMER_QUEUE* queue1,CUSTOMER_QUEUE* queue2,
CUSTOMER_QUEUE* queue3,CUSTOMER_QUEUE* queue4,int timeout){
out_queue(queue1,timeout);out_queue(queue2,timeout);
out_queue(queue3,timeout);out_queue(queue4,timeout);
return 1;
}

int in(CUSTOMER_QUEUE* queue1,CUSTOMER_QUEUE* queue2,
CUSTOMER_QUEUE* queue3,CUSTOMER_QUEUE* queue4,CUSTOMER* customer){
CUSTOMER_QUEUE* ptr=least_waiting_time(queue1,queue2,queue3,queue4);
customer->waiting_time = ptr->teller_waiting_list_time;
ptr->teller_waiting_list_time += customer->need_service_time;
ptr->teller_service_customers++;ptr->teller_waiting_time_all += customer->waiting_time;
customer_queue_in(ptr,customer);
return 1;
}

int run(CUSTOMER_LIST* customer_list,CUSTOMER_QUEUE* queue1,CUSTOMER_QUEUE* queue2,
CUSTOMER_QUEUE* queue3,CUSTOMER_QUEUE* queue4){
int waiting_list_time;
CUSTOMER* ptr;
int time=0,timeout;
while(1){
ptr=pop_customer_list(customer_list);
if( ptr == &(customer_list->tail) ) break;
timeout=ptr->arrive_time-time;
out(queue1,queue2,queue3,queue4,timeout);
in(queue1,queue2,queue3,queue4,ptr);
time=ptr->arrive_time;
}
waiting_list_time=max_waiting_list_time(queue1,queue2,queue3,queue4);
out(queue1,queue2,queue3,queue4,waiting_list_time);
int time_all=100+waiting_list_time;

queue1->teller_free_time = time_all - queue1->teller_service_time;
queue2->teller_free_time = time_all - queue2->teller_service_time;
queue3->teller_free_time = time_all - queue3->teller_service_time;
queue4->teller_free_time = time_all - queue4->teller_service_time;

printf("queue1 service_time:%d,service_customer:%d,customer_avag_waitime:%d,queue_free_time:%d,customer_avar_waitime:%d\n",queue1->teller_service_time,queue1->teller_service_customers,queue1->teller_waiting_time_all,queue1->teller_free_time,(queue1->teller_waiting_time_all)/(queue1->teller_service_time));
printf("queue2 service_time:%d,service_customer:%d,customer_avag_waitime:%d,queue_free_time:%d,customer_avar_waitime:%d\n",queue2->teller_service_time,queue2->teller_service_customers,queue2->teller_waiting_time_all,queue2->teller_free_time,(queue2->teller_waiting_time_all)/(queue2->teller_service_time));
printf("queue3 service_time:%d,service_customer:%d,customer_avag_waitime:%d,queue_free_time:%d,customer_avar_waitime:%d\n",queue3->teller_service_time,queue3->teller_service_customers,queue3->teller_waiting_time_all,queue3->teller_free_time,(queue3->teller_waiting_time_all)/(queue3->teller_service_time));
printf("queue4 service_time:%d,service_customer:%d,customer_avag_waitime:%d,queue_free_time:%d,customer_avar_waitime:%d\n",queue4->teller_service_time,queue4->teller_service_customers,queue4->teller_waiting_time_all,queue4->teller_free_time,(queue4->teller_waiting_time_all)/(queue4->teller_service_time));
return 1;
}

//--------------------------------------------
int main(){
CUSTOMER_QUEUE queue1,queue2,queue3,queue4;
init_customer_queue(&queue1);init_customer_queue(&queue2);
init_customer_queue(&queue3);init_customer_queue(&queue4);

CUSTOMER_LIST customer_list;
create_customer_list(&customer_list);

CUSTOMER *ptr=customer_list.head.nex_ptr;
while(ptr->nex_ptr != NULL){
printf("arrive_time:%d,need_service_time:%d\n",ptr->arrive_time,ptr->need_service_time);
ptr=ptr->nex_ptr;
}
//-------------------------------
run(&customer_list,&queue1,&queue2,&queue3,&queue4);
return 0;
}

#include<stdio.h>
#include<stdlib.h>

typedef struct edgenode{
char from;
char to;
int cost;
struct edgenode* nex_ptr;
}EDGENODE;

typedef struct nodelist{
int node_num;
EDGENODE head;
EDGENODE tail;
}NODELIST;

int initnodelist(NODELIST* list){
list->node_num=0;
list->head.cost=-1;list->tail.cost=-1;
list->head.nex_ptr=&(list->tail);
list->tail.nex_ptr=NULL;
}

int createlist(NODELIST* list){
EDGENODE *ptr,*ptr_list;
EDGENODE *ptr_num;
int flag1,flag2;
char tmp;
printf("edgenode from:to:cost:,input as format a\\tb\\tc\\n,end with '#':\n");
while(1){
flag1=1;flag2=1;
ptr=malloc(sizeof(EDGENODE));
scanf("%c",&(ptr->from));
if(ptr->from == '#') break;
scanf("%c",&tmp);
scanf("%c",&(ptr->to));
scanf("%c",&tmp);
scanf("%d",&(ptr->cost));
scanf("%c",&tmp);

if(list->head.nex_ptr == &(list->tail)){
list->head.nex_ptr=ptr;ptr->nex_ptr=&(list->tail);
list->node_num += 2;
}else{
ptr_list=&(list->head);
ptr_num=list->head.nex_ptr;
while(1){
if( ptr_num->from == ptr->from || ptr_num->to == ptr->from ) flag1=0;
if( ptr_num->from == ptr->to || ptr_num->to == ptr->to ) flag2=0;
if( ptr_num->nex_ptr == &(list->tail) ) break;
ptr_num=ptr_num->nex_ptr;
}
list->node_num += (flag1+flag2);

while(1){
if( ptr_list->nex_ptr->cost >= ptr->cost ){
ptr->nex_ptr=ptr_list->nex_ptr;
ptr_list->nex_ptr=ptr;break;
}
if( ptr_list->nex_ptr == &(list->tail) ){
ptr->nex_ptr=&(list->tail);
ptr_list->nex_ptr=ptr;
break;
}
ptr_list=ptr_list->nex_ptr;
}
}
}
return 1;
}

EDGENODE* poplist(NODELIST* list){
EDGENODE* ptr;
if( list->head.nex_ptr == &(list->tail) ){
return &(list->tail);
}else{
ptr=list->head.nex_ptr;
list->head.nex_ptr=list->head.nex_ptr->nex_ptr;
return ptr;
}
}

//-------------------------------------------------------------------------
typedef struct node{
char c;
struct node* nex_node;
}NODE;

typedef struct union_node{
NODE* head;
NODE* tail;
struct union_node* nex_union_node;
}UNION_NODE;

typedef struct union_list{
//int node_num;
UNION_NODE head;
UNION_NODE tail;
}UNION_LIST;

int initunion_list(UNION_LIST* list){
//list->node_num=0;
list->head.nex_union_node=&(list->tail);
list->tail.nex_union_node=NULL;
return 1;
}

UNION_NODE* find(UNION_LIST* list,char find_c){
UNION_NODE* ptr_union_node=list->head.nex_union_node;
NODE* ptr_node;
while( ptr_union_node->nex_union_node != NULL ){
ptr_node=ptr_union_node->head;
while(1){
if( ptr_node->c == find_c ){
return ptr_union_node;
}
if( ptr_node == ptr_union_node->tail ) break;
ptr_node=ptr_node->nex_node;
}
ptr_union_node=ptr_union_node->nex_union_node;
}
return NULL;
}

UNION_NODE* creat_union_node(UNION_LIST* list){
UNION_NODE* ptr=malloc(sizeof(UNION_NODE));
ptr->nex_union_node=list->head.nex_union_node;
list->head.nex_union_node=ptr;
ptr->head=NULL; ptr->tail=NULL;
return ptr;
}

int del_union_node(UNION_LIST* list){
UNION_NODE* ptr_union_node=&(list->head);
UNION_NODE* tmp;
while( ptr_union_node->nex_union_node != NULL ){
if( ptr_union_node->nex_union_node->head == NULL ){
tmp=ptr_union_node->nex_union_node;
ptr_union_node->nex_union_node=tmp->nex_union_node;
free(tmp);
}
ptr_union_node=ptr_union_node->nex_union_node;
}
return 1;
}

int unite_union_node(UNION_LIST* list,UNION_NODE* union_node1,UNION_NODE* union_node2){
if( union_node1->head == NULL || union_node2->head == NULL ) return 0;
NODE* ptr=union_node2->head;
union_node1->tail->nex_node=ptr;
union_node1->tail=union_node2->tail;
union_node2->head=NULL;
del_union_node(list);
return 1;
}

int creat_node(UNION_NODE* ptr,char c){
NODE* node_ptr=malloc(sizeof(NODE));
node_ptr->c=c;
if( ptr->head == NULL ){
ptr->head=node_ptr;
ptr->tail=node_ptr;
}else{
ptr->tail->nex_node=node_ptr;
ptr->tail=node_ptr;
node_ptr->nex_node=NULL;
}
return 1;
}

int add_two_char(UNION_LIST* list,char from,char to){
UNION_NODE *ptr1,*ptr2;
UNION_NODE* new_ptr;
ptr1=find(list,from);ptr2=find(list,to);
if( ptr1 != NULL && ptr2 != NULL ){
if( ptr1==ptr2 ){
return 0;
}else{
unite_union_node(list,ptr1,ptr2);
}
}else if( ptr1 != NULL && ptr2 == NULL ){
creat_node(ptr1,to);//list->node_num++;
}else if( ptr1 == NULL && ptr2 != NULL ){
creat_node(ptr2,from);//list->node_num++;
}else if( ptr1 == NULL && ptr2 ==NULL ){
new_ptr=creat_union_node(list);
creat_node(new_ptr,from);creat_node(new_ptr,to);
//list->node_num += 2;
}

return 1;
}

int trav_union_list(UNION_LIST* list){
UNION_NODE* ptr_union_node=list->head.nex_union_node;
NODE* ptr_node;
//printf("there is %d nodes\n",list->node_num);
while( ptr_union_node->nex_union_node != NULL ){
ptr_node=ptr_union_node->head;
printf("line:");
while(1){
printf("%c",ptr_node->c);
if( ptr_node == ptr_union_node->tail ) break;
ptr_node=ptr_node->nex_node;
}
printf("\n");
ptr_union_node=ptr_union_node->nex_union_node;
}
return 1;

}

//-------------------------------------------------------------------------

int run(NODELIST* nodelist,UNION_LIST* union_list){
int cost=0;
int line=0;
EDGENODE* ptr;
printf("smallest tree:\n");
while( (ptr=poplist(nodelist)) != &(nodelist->tail) && line < nodelist->node_num-1 ){
if( add_two_char(union_list,ptr->from,ptr->to) == 0 ) continue;
else{
printf("%c,%c,%d\n",ptr->from,ptr->to,ptr->cost);
cost += ptr->cost;
line++;
}
}
if( line < nodelist->node_num-1 ) printf("is not a smallest tree\n");
else printf("that is the smallest tree,the smallest cost is %d\n",cost);
return 1;
}


//-------------------------------------------------------------------------

int main(){
EDGENODE* ptr;

UNION_LIST union_list;
initunion_list(&union_list);

NODELIST list;
initnodelist(&list);
createlist(&list);

//printf("the node_num:");
//scanf("%d",&(union_list.node_num));
run(&list,&union_list);
return 0;
}

雨天

在我的印象里,北京是很少下雨的,这是一个干燥的城市。
这两天雨纷纷扬扬下着,今天又转为小雪的天气。我靠着窗户,想起了家乡的四月,那种曾经诅咒过得的细雨绵绵的天气,想起水泥墙溢出的水滴……冥冥之中有一种想念的味道。
前一段时间和一位朋友聊天,她告诉我,她很少会想起过去,她要忘记过去,眼光里只有未来。坦诚的谈话使我才真的有一点了解她:了解一个人,不像想像中那么容易。
而我,感觉自己是一个背负着十字架游走的忏悔者,十字架上面刻着两个字:过去,我步履维艰……
梦魇般的时间过去了,前面,又是一个怎样的未来?
前面,路正漫……

挑战呀!

今天没事就看看“前辈们”招聘工作的文章,我重点看了看yahoo,163,baidu的几个招聘经历,因为我对这几个公司都非常感兴趣。感觉工作可真是不好找,压力真是挺大的,有不少名校毕业生,甚至研究生,开始工作时也就5K/m,并且对外地学生,户口也是一个大问题。有一些大企业,其实招聘目标就是重点院校学生,其他的都排除了。唉,前面,路正漫……

svg和shell脚本的结合

今天做了一个有趣的svg+shell:
原理如下,把svg图片分成三个部分,如下:
azhoulinux@azhou:~/Desktop$ cat 1 2 3
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="800"
height="600"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.44.1"
sodipodi:docbase="/home/azhoulinux"
sodipodi:docname="test.svg">
<metadata
id="metadata1901">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
inkscape:window-height="583"
inkscape:window-width="819"
guidetolerance="10.0"
gridtolerance="10.0"
objecttolerance="10.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base"
inkscape:zoom="0.63"
inkscape:cx="396.40833"
inkscape:cy="300"
inkscape:window-x="4"
inkscape:window-y="67"
inkscape:current-layer="layer1" />
<defs
id="defs4" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:none;fill-rule:evenodd;stroke:blue;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:2"
d="M 120,120 L 130,120 L 120,90 L 120,500 L 750,500 L 720,490 L 720,500 "
id="path1905"
sodipodi:nodetypes="c" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect1915"
width="630"
height="30"
x="120"
y="470" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2811"
width="630"
height="30"
x="120"
y="440" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2813"
width="630"
height="30"
x="120"
y="410" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2815"
width="630"
height="30"
x="120"
y="380" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2817"
width="630"
height="30"
x="120"
y="350" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2819"
width="630"
height="30"
x="120"
y="320" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2821"
width="630"
height="30"
x="120"
y="290" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2823"
width="630"
height="30"
x="120"
y="260" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2825"
width="630"
height="30"
x="120"
y="230" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2827"
width="630"
height="30"
x="120"
y="200" />
<rect
style="opacity:0.28947368;fill:#df7d3d;fill-opacity:1;stroke:black;stroke-opacity:1"
id="rect2829"
width="630"
height="30"
x="120"
y="170" />

<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="500"
id="text2778"><tspan
sodipodi:role="line"
id="tspan2780"
x="100"
y="500">0.0</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="470"
id="text2778"><tspan
sodipodi:role="line"
id="tspan2780"
x="100"
y="470">0.1</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="440"
id="text2788"><tspan
sodipodi:role="line"
id="tspan2790"
x="100"
y="440">0.2</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="410"
id="text2792"><tspan
sodipodi:role="line"
id="tspan2794"
x="100"
y="410">0.3</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="380"
id="text2796"><tspan
sodipodi:role="line"
id="tspan2798"
x="100"
y="380">0.4</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="350"
id="text2800"><tspan
sodipodi:role="line"
id="tspan2802"
x="100"
y="350">0.5</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="320"
id="text2804"><tspan
sodipodi:role="line"
id="tspan2806"
x="100"
y="320">0.6</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="290"
id="text2808"><tspan
sodipodi:role="line"
id="tspan2810"
x="100"
y="290">0.7</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="260"
id="text2812"><tspan
sodipodi:role="line"
id="tspan2814"
x="100"
y="260">0.8</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="230"
id="text2816"><tspan
sodipodi:role="line"
id="tspan2818"
x="100"
y="230">0.9</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="200"
id="text2820"><tspan
sodipodi:role="line"
id="tspan2822"
x="100"
y="200">1.0</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="100"
y="170"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="100"
y="170">1.5</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="150"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="150"
y="510">1</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="180"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="180"
y="510">2</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="210"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="210"
y="510">3</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="240"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="240"
y="510">4</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="270"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="270"
y="510">5</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="300"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="300"
y="510">6</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="330"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="330"
y="510">7</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="370"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="370"
y="510">8</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="400"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="400"
y="510">9</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="430"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="430"
y="510">10</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="460"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="460"
y="510">11</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="490"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="490"
y="510">12</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="520"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="520"
y="510">13</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="550"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="550"
y="510">14</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="580"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="580"
y="510">15</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="610"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="610"
y="510">16</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="640"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="640"
y="510">17</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="670"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="670"
y="510">18</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="700"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="700"
y="510">19</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="730"
y="510"
id="text2824"><tspan
sodipodi:role="line"
id="tspan2826"
x="730"
y="510">20</tspan></text>
<path
style="fill:none;fill-rule:evenodd;stroke:red;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:2"
d="
##========================================以上是文件第一部分,part1

##========================================以上为文件第二部分,part2
"
id="path1905"
sodipodi:nodetypes="c" />

</g>

##========================================以上为文件第三部分,part3

其中文件二有shell脚本生成,最后使用以下命令合成test.svg:

azhoulinux@azhou:~/Desktop$ cat 1 2 3 > test.svg

shell脚本如下:test.sh
azhoulinux@azhou:~/Desktop$ cat test.sh
#!/bin/bash
#by azhoulinux 2006-12-2

#first part init var
startx=120
starty=500
countnum=0

#second get the x y
while [ true ]
do
x=$startx
y=$starty
loadavg=`uptime |awk '{print $8}'|awk -F , '{print $1}'`
# echo $loadavg
suby=`echo "$loadavg*300"|bc|awk -F . '{print $1}'`
# echo "$suby \c"
# echo "\c"
let x="120+30*$countnum"
let y="$y-$suby"
if [ $countnum = 0 ]
then
echo "M${x},${y}" >>2
else
echo "L${x},${y}" >>2
fi
cat 1 2 3 > test.svg
let countnum="$countnum+1"
if [ $countnum = 21 ]
then
cat /dev/null > 2
countnum=0
fi

# echo $x
# echo $y
sleep 1s
done

而test.html要起到自动刷新功能,代码如下:
azhoulinux@azhou:~/Desktop$ cat test.html
<html>
<head>
<meta http-equiv=refresh content=1 />
</head>
<body>
embed src="test.svg" width="800" height="600"/
</body>
</html>

这样每一秒就会自动刷新页面,而文件二每一秒就自动更新。效果如下:

写了一个长长的脚本

#给一位朋友写了这个脚本,是近一段时间来学习的总结
#!/bin/bash
# first we will check the time , using `date` will get the time , and awk get
# what we want

# first part
function checktime() {
timenow=`date|awk '{print $5}'|awk -F : '{print $1}'`

case "$timenow" in
0[0-6])
echo "it is the sleeping time ,have a good dream"
;;
0[7-9]|1[0-2])
echo "good morning,have a good day !"
;;
1[3-8])
echo "good afternoon,have tea !"
;;
1[9]|2[0-3])
echo "it is the evening,watching TV now !"
;;
esac

}

# second part ,check mail,you will check the file /var/mail/USER,
#and chose the mail from root
function checkmail() {
echo "now will check the mail from root :"
echo "\n"
mailcount=`grep "From: root" /var/mail/$USER |wc -l`
if [ $mailcount -ne 0 ]
then echo "you have $mailcount mails from root ,do you want to read now ? press y or n"
read answer
if [ $answer = "y" ]
then mail
fi
fi
}

#check if file memo exist , if yes ,show it
function checkmemo() {
echo "now will check file memo to remind you something:"
if [ -f ~/memo ]
then
echo "you have file memo in your home dir ,maybe you have write someting"
cat ~/memo
else
echo "can not find memo, do you forget someting"
fi
}

#export var wdir ,that is your working dir
export wdir="$HOME/project"

#backup the files in $wdir to $HOME/backup
function backupwdir() {
echo "start to backup:"
tar -cvf $HOME/backup/project.tar $wdir
echo "backup complete !"
}

#check if to backup
function ifbackup() {
echo "check if you want to backup:"
if [ -d $wdir ]
then
if [ -f $HOME/backup/project.tar ]
then
backupdate=` ls -l $HOME/backup/project.tar |awk '{print $6}'`
if [ $backupdate = `date +%F` ]
then
echo "backup in the same day ,do not need to backup"
else
backupwdir;
fi
else
echo "can not find backup file ,try to backup"
backupwdir;
fi
else
echo "can not find dir $wdir,maybe have to check the working dir !"
fi
}

#the main part of this script :
checktime ;
checkmail ;
checkmemo ;
ifbackup ;
echo "all done !"

今天更新了perl搜索脚本_V0.9 :)

昨天的脚本有一个非常大的问题,就是如果在搜索一个关键字时,如果是目录,就会把目录里所有的文件都列出来,因为目录名也是关键字的一部分,这样搜索时会出现太多的信息,现在换一种方式,如下:
就是搜索时以文件名为单位,如果文件名匹配,才显示出来。
需要以下几个文件:
ftp.list // cd到/home/ftp目录,使用find ./>ftp.list创建ftp.list文件
se_ftp.list //使用awk -F / '{print NR ":" $NF}' ftp.list
num.list // 作为缓存符合条件的行数
其中最为关键的两个脚本如下:
##======================================
azhoulinux@azhou:~/Desktop$ cat search.pl
#!/usr/bin/perl
##
## To Search the ftp
##
$finfo = <STDIN>;
print "Content-type: text/plain; charset=gb2312 \n\n";
$se_name=`echo $finfo|cut -c 5-` ;
print "you have search for:";
print $se_name;
print "\n\n";
print `./search.sh $se_name`;
exit(0);

##======================================
azhoulinux@azhou:~/Desktop$ cat search.sh
#!/bin/bash

var_char=`awk -F : '{print $0}' se_ftp.list|grep -i "$1"|awk -F : '{print $1}'`


echo "">num_list

for i in `echo $var_char`
do

echo "-e ${i}p">>num_list

done

sed -n `cat num_list` ftp.list|cut -c 3-|awk -F / '{print NR " " $NF "\n" "ftp://211.68.42.243/" $0 "\n"}'

这样就可以搜索了,并且没有上面问题:
附图:


使用perl编写cgi

CGI stands for Common Gateway Interface:
CGI 是网站主机与外部程序沟通的界面标准,只要输出符合这个标准的程序都通称为CGI,最普遍使用来撰写CGI 的是Perl Script。
今天我想写一个搜索关键字的perl脚本,最后如下,
1 在/home/ftp下运行
shell>find /home/ftp > /home/server/http2/cgi-bin/ftp.list
就可以把/home/ftp下的文件和目录都列出重定向到文本文件ftp.list

2 配置perl mod如下
azhoulinux@mail:/tmp/mod_perl-2.0.2$ sed -n '1,5p' INSTALL
Simple install:

% perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
% make && make test
% make install
这个就是安装方法,配置方法如下:
azhoulinux@mail:/tmp/mod_perl-2.0.2$ sed -n '6,12p' INSTALL

Simple config:

LoadModule perl_module modules/mod_perl.so
#PerlModule Apache::compat
# your config comes here
之后重启apache就可以了。
我写了以下几个脚本(放在/cgi-bin目录下):
test.pl
mail:/home/server/httpd/cgi-bin# cat test.pl
#!/usr/bin/perl
##
## this is very simple ,you need to see test.sh
## to accept the input from other pages
$finfo = <STDIN>;
## set the charset ,and is needed if you like to use it as cgi
print "Content-type: text/plain; charset=gb2312 \n\n";
## to change it a little
$se_name=`echo $finfo|cut -c 5-`;
## put the output
print $se_name;
print `./test.sh '$se_name'`;
exit(0);

test.sh
mail:/home/server/httpd/cgi-bin# cat test.sh
#!/bin/bash
#print $1 ;
cat ftp.list|grep -i $1 |cut -c 2- - |awk -F / '{print NR " " $NF "\n" "ftp://211.68.42.243" $0 "\n"}' -

##----------------------------------

然后在页面上有一个form来传递变量,如下:

form method="POST" action="/cgi-bin/test.pl"
input size="40" maxlength="100" type="text" name="put"
input type="submit" value="SSA search"
/form

这样就把变量put传给了test.pl,由test.pl来处理这个变量.
这一次是头一次进行perl编脚本,还是这么有趣的脚本,呵呵
不过cgi有很多危险的地方,按照书上说的是:
cgi天生就是不安全的
比如上面脚本,如果有一个人恶意在input上填了“XX;rm -rf /;“
这样有可能XX作为一个变量传递,而“;“之后被shell看成新的命令行,如果执行者就比较大的权限,那就会删除很多东西。
July 2009
S M T W T F S
June 2009August 2009
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31