//顏色初始化 if(!has_colors() || start_color() == ERR){ endwin() printf("Terminal does not support color.\n") exit(1) } init_pair(1, COLOR_GREEN, COLOR_BLACK) init_pair(2, COLOR_RED, COLOR_BLACK) init_pair(3, COLOR_CYAN, COLOR_BLACK) init_pair(4, COLOR_WHITE, COLOR_BLACK) init_pair(5, COLOR_MAGENTA, COLOR_BLACK) init_pair(6, COLOR_BLUE, COLOR_BLACK) init_pair(7, COLOR_YELLOW, COLOR_BLACK) //寫字符串 for(i = 1 i <= 7 i++) { attron(COLOR_PAIR(i)) printw("color pair d in normal mode\n", i) } for(i = 1 i <= 7 i++) { attron(COLOR_PAIR(i) | A_BLINK | A_UNDERLINE) printw("color pair d in normal mode\n", i) }
標簽: start_color has_colors Terminal endwin
上傳時間: 2014-01-14
上傳用戶:vodssv
g a w k或GNU awk是由Alfred V. A h o,Peter J.We i n b e rg e r和Brian W. K e r n i g h a n于1 9 7 7年為U N I X創(chuàng)建的a w k編程語言的較新版本之一。a w k出自創(chuàng)建者姓的首字母。a w k語言(在其所有的版本中)是一種具有很強能力的模式匹配和過程語言。a w k獲取一個文件(或多個文件)來查找匹配特定模式的記錄。當查到匹配后,即執(zhí)行所指定的動作。作為一個程序員,你不必操心通過文件打開、循環(huán)讀每個記錄,控制文件的結(jié)束,或執(zhí)行完后關(guān)閉文件。
上傳時間: 2014-01-02
上傳用戶:hwl453472107
#include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NULL 0 #define MaxSize 30 typedef struct athletestruct /*運動員*/ { char name[20]; int score; /*分數(shù)*/ int range; /**/ int item; /*項目*/ }ATH; typedef struct schoolstruct /*學校*/ { int count; /*編號*/ int serial; /**/ int menscore; /*男選手分數(shù)*/ int womenscore; /*女選手分數(shù)*/ int totalscore; /*總分*/ ATH athlete[MaxSize]; /**/ struct schoolstruct *next; }SCH; int nsc,msp,wsp; int ntsp; int i,j; int overgame; int serial,range; int n; SCH *head,*pfirst,*psecond; int *phead=NULL,*pafirst=NULL,*pasecond=NULL; void create(); void input () { char answer; head = (SCH *)malloc(sizeof(SCH)); /**/ head->next = NULL; pfirst = head; answer = 'y'; while ( answer == 'y' ) { Is_Game_DoMain: printf("\nGET Top 5 when odd\nGET Top 3 when even"); printf("\n輸入運動項目序號 (x<=%d):",ntsp); scanf("%d",pafirst); overgame = *pafirst; if ( pafirst != phead ) { for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ ) { if ( overgame == *pasecond ) { printf("\n這個項目已經(jīng)存在請選擇其他的數(shù)字\n"); goto Is_Game_DoMain; } } } pafirst = pafirst + 1; if ( overgame > ntsp ) { printf("\n項目不存在"); printf("\n請重新輸入"); goto Is_Game_DoMain; } switch ( overgame%2 ) { case 0: n = 3;break; case 1: n = 5;break; } for ( i = 1 ; i <= n ; i++ ) { Is_Serial_DoMain: printf("\n輸入序號 of the NO.%d (0<x<=%d): ",i,nsc); scanf("%d",&serial); if ( serial > nsc ) { printf("\n超過學校數(shù)目,請重新輸入"); goto Is_Serial_DoMain; } if ( head->next == NULL ) { create(); } psecond = head->next ; while ( psecond != NULL ) { if ( psecond->serial == serial ) { pfirst = psecond; pfirst->count = pfirst->count + 1; goto Store_Data; } else { psecond = psecond->next; } } create(); Store_Data: pfirst->athlete[pfirst->count].item = overgame; pfirst->athlete[pfirst->count].range = i; pfirst->serial = serial; printf("Input name:) : "); scanf("%s",pfirst->athlete[pfirst->count].name); } printf("\n繼續(xù)輸入運動項目(y&n)?"); answer = getchar(); printf("\n"); } } void calculate() /**/ { pfirst = head->next; while ( pfirst->next != NULL ) { for (i=1;i<=pfirst->count;i++) { if ( pfirst->athlete[i].item % 2 == 0 ) { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 5;break; case 2:pfirst->athlete[i].score = 3;break; case 3:pfirst->athlete[i].score = 2;break; } } else { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 7;break; case 2:pfirst->athlete[i].score = 5;break; case 3:pfirst->athlete[i].score = 3;break; case 4:pfirst->athlete[i].score = 2;break; case 5:pfirst->athlete[i].score = 1;break; } } if ( pfirst->athlete[i].item <=msp ) { pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score; } else { pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score; } } pfirst->totalscore = pfirst->menscore + pfirst->womenscore; pfirst = pfirst->next; } } void output() { pfirst = head->next; psecond = head->next; while ( pfirst->next != NULL ) { // clrscr(); printf("\n第%d號學校的結(jié)果成績:",pfirst->serial); printf("\n\n項目的數(shù)目\t學校的名字\t分數(shù)"); for (i=1;i<=ntsp;i++) { for (j=1;j<=pfirst->count;j++) { if ( pfirst->athlete[j].item == i ) { printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break; } } } printf("\n\n\n\t\t\t\t\t\t按任意建 進入下一頁"); getchar(); pfirst = pfirst->next; } // clrscr(); printf("\n運動會結(jié)果:\n\n學校編號\t男運動員成績\t女運動員成績\t總分"); pfirst = head->next; while ( pfirst->next != NULL ) { printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore); pfirst = pfirst->next; } printf("\n\n\n\t\t\t\t\t\t\t按任意建結(jié)束"); getchar(); } void create() { pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct)); pfirst->next = head->next ; head->next = pfirst ; pfirst->count = 1; pfirst->menscore = 0; pfirst->womenscore = 0; pfirst->totalscore = 0; } void Save() {FILE *fp; if((fp = fopen("school.dat","wb"))==NULL) {printf("can't open school.dat\n"); fclose(fp); return; } fwrite(pfirst,sizeof(SCH),10,fp); fclose(fp); printf("文件已經(jīng)成功保存\n"); } void main() { system("cls"); printf("\n\t\t\t 運動會分數(shù)統(tǒng)計\n"); printf("輸入學校數(shù)目 (x>= 5):"); scanf("%d",&nsc); printf("輸入男選手的項目(x<=20):"); scanf("%d",&msp); printf("輸入女選手項目(<=20):"); scanf("%d",&wsp); ntsp = msp + wsp; phead = (int *)calloc(ntsp,sizeof(int)); pafirst = phead; pasecond = phead; input(); calculate(); output(); Save(); }
標簽: 源代碼
上傳時間: 2016-12-28
上傳用戶:150501
1.Describe a Θ(n lg n)-time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. (Implement exercise 2.3-7.) #include<stdio.h> #include<stdlib.h> void merge(int arr[],int low,int mid,int high){ int i,k; int *tmp=(int*)malloc((high-low+1)*sizeof(int)); int left_low=low; int left_high=mid; int right_low=mid+1; int right_high=high; for(k=0;left_low<=left_high&&right_low<=right_high;k++) { if(arr[left_low]<=arr[right_low]){ tmp[k]=arr[left_low++]; } else{ tmp[k]=arr[right_low++]; } } if(left_low<=left_high){ for(i=left_low;i<=left_high;i++){ tmp[k++]=arr[i]; } } if(right_low<=right_high){ for(i=right_low;i<=right_high;i++) tmp[k++]=arr[i]; } for(i=0;i<high-low+1;i++) arr[low+i]=tmp[i]; } void merge_sort(int a[],int p,int r){ int q; if(p<r){ q=(p+r)/2; merge_sort(a,p,q); merge_sort(a,q+1,r); merge(a,p,q,r); } } int main(){ int a[8]={3,5,8,6,4,1,1}; int i,j; int x=10; merge_sort(a,0,6); printf("after Merging-Sort:\n"); for(i=0;i<7;i++){ printf("%d",a[i]); } printf("\n"); i=0;j=6; do{ if(a[i]+a[j]==x){ printf("exist"); break; } if(a[i]+a[j]>x) j--; if(a[i]+a[j]<x) i++; }while(i<=j); if(i>j) printf("not exist"); system("pause"); return 0; }
上傳時間: 2017-04-01
上傳用戶:糖兒水嘻嘻
# include<stdio.h> # include<math.h> # define N 3 main(){ float NF2(float *x,float *y); float A[N][N]={{10,-1,-2},{-1,10,-2},{-1,-1,5}}; float b[N]={7.2,8.3,4.2},sum=0; float x[N]= {0,0,0},y[N]={0},x0[N]={}; int i,j,n=0; for(i=0;i<N;i++) { x[i]=x0[i]; } for(n=0;;n++){ //計算下一個值 for(i=0;i<N;i++){ sum=0; for(j=0;j<N;j++){ if(j!=i){ sum=sum+A[i][j]*x[j]; } } y[i]=(1/A[i][i])*(b[i]-sum); //sum=0; } //判斷誤差大小 if(NF2(x,y)>0.01){ for(i=0;i<N;i++){ x[i]=y[i]; } } else break; } printf("經(jīng)過%d次雅可比迭代解出方程組的解:\n",n+1); for(i=0;i<N;i++){ printf("%f ",y[i]); } } //求兩個向量差的二范數(shù)函數(shù) float NF2(float *x,float *y){ int i; float z,sum1=0; for(i=0;i<N;i++){ sum1=sum1+pow(y[i]-x[i],2); } z=sqrt(sum1); return z; }
上傳時間: 2019-10-13
上傳用戶:大萌萌撒
1.2 源代碼表示不考慮主題,列舉 15 000行源代碼本身就是一件難事。下面是所有源代碼都使用的文本格式:1.2.1 將擁塞窗口設(shè)置為13 8 7 - 3 8 8 這是文件t c p _ s u b r . c中的函數(shù)t c p _ q u e n c h。這些源文件名引用4 . 4 B S D - L i t e發(fā)布的文件。4 . 4 B S D在1 . 1 3節(jié)中討論。每個非空白行都有編號。正文所描述的代碼的起始和結(jié)束位置的行號記于行開始處,如本段所示。有時在段前有一個簡短的描述性題頭,對所描述的代碼提供一個概述。這些源代碼同4 . 4 B S D - L i t e發(fā)行版一樣,偶爾也包含一些錯誤,在遇到時我們會提出來并加以討論,偶爾還包括一些原作者的編者評論。這些代碼已通過了 G N U縮進程序的運行,使它們從版面上看起來具有一致性。制表符的位置被設(shè)置成 4個欄的界線使得這些行在一個頁面中顯示得很合適。在定義常量時,有些 # i f d e f語句和它們的對應(yīng)語句 # e n d i f被刪去(如:G A T E W A Y和M R O U T I N G,因為我們假設(shè)系統(tǒng)被作為一個路由器或多播路由器 )。所有r e g i s t e r說明符被刪去。有些地方加了一些注釋,并且一些注釋中的印刷錯誤被修改了,但代碼的其他部分被保留下來。這些函數(shù)大小不一,從幾行 (如前面的t c p _ q u e n c h)到最大11 0 0行(t c p _ i n p u t)。超過大約4 0行的函數(shù)一般被分成段,一段一段地顯示。雖然盡量使代碼和相應(yīng)的描述文字放在同一頁或?qū)﹂_的兩頁上,但為了節(jié)約版面,不可能完全做到。本書中有很多對其他函數(shù)的交叉引用。為了避免給每個引用都添加一個圖號和頁碼,書封底內(nèi)頁中有一個本書中描述的所有函數(shù)和宏的字母交叉引用表和描述的起始頁碼。因為本書的源代碼來自公開的 4 . 4 B S D _ L i t e版,因此很容易獲得它的一個拷貝:附錄 B詳細說明了各種方法。當你閱讀文章時,有時它會幫助你搜索一個在線拷貝 [例如U n i x程序grep ( 1 )]。描述一個源代碼模塊的各章通常以所討論的源文件的列表開始,接著是全局變量、代碼維護的相關(guān)統(tǒng)計以及一個實際系統(tǒng)的一些例子統(tǒng)計,最后是與所描述協(xié)議相關(guān)的 S N M P變量。全局變量的定義通常跨越各種源文件和頭文件,因此我們將它們集中到的一個表中以便于參考。這樣顯示所有的統(tǒng)計,簡化了后面當統(tǒng)計更新時對代碼的討論。卷 1的第2 5章提供了S N M P的所有細節(jié)。我們在本文中關(guān)心的是由內(nèi)核中的 T C P / I P例程維護的、支持在系統(tǒng)上運行的S N M P代理的信息。TCP IP詳解 卷1協(xié)議 :http://dl.21ic.com/download/tcpip-288223.html TCP IP詳解 卷2實現(xiàn) :http://dl.21ic.com/download/tcpip-288224.html TCPIP詳解卷三:TCP事務(wù)協(xié)議,HTTP,NNTP和UNIX域協(xié)議 :http://dl.21ic.com/download/tcpip-288225.html
上傳時間: 2022-07-27
上傳用戶:
LinQ SQL TẤ N CÔ NG KIỂ U SQL INJECTION - TÁ C HẠ I VÀ PHÒ NG TRÁ NH
上傳時間: 2013-12-15
上傳用戶:eclipse
n個石頭(每相鄰兩個的距離是1米,最邊上石頭和岸的距離也是1米),禮物放在第m個石頭上,青蛙第i次跳2*i-1米.問能否得到禮物.(n>=49肯定能得到禮物,n<49,可以bfs或遞歸)
上傳時間: 2013-12-30
上傳用戶:linlin
本章介紹L i n u x內(nèi)核是如何維護它支持的文件系統(tǒng)中的文件的.
標簽: 內(nèi)核 文件系統(tǒng)
上傳時間: 2014-12-04
上傳用戶:xmsmh
程序存儲問題:設(shè)有n 個程序{1,2,…, n }要存放在長度為L的磁帶上。程序i存放在磁帶上的長度是Li ,1≤i≤n 程序存儲問題要求確定這n 個程序在磁帶上的一個存儲方案,使得能夠在磁帶上存儲盡可能多的程序。 編程任務(wù): 對于給定的n個程序存放在磁帶上的長度,編程計算磁帶上最多可以存儲的程序數(shù)。 數(shù)據(jù)輸入:由文件input.txt給出輸入數(shù)據(jù)。第一行是正整數(shù)n,表示文件個數(shù)。接下來的1 行中,有n 個正整數(shù),表示程序存放在磁帶上的長度。 結(jié)果輸出: input.txt output.txt 6 50 5 2 3 13 8 80 20
上傳時間: 2013-12-20
上傳用戶:dongqiangqiang
蟲蟲下載站版權(quán)所有 京ICP備2021023401號-1