西工大C語言POJ作業(yè)._第1頁
西工大C語言POJ作業(yè)._第2頁
西工大C語言POJ作業(yè)._第3頁
西工大C語言POJ作業(yè)._第4頁
西工大C語言POJ作業(yè)._第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、T071、大數(shù)乘法#include <stdio.h>#include <string.h>#include <stdlib.h>void cheng(char a,char b) int i,j,ca,cb,*s; ca=strlen(a); cb=strlen(b); s=(int *)malloc(sizeof(int)*(ca+cb); /分配存儲空間 for (i=0;i<ca+cb;i+) si=0; / 每個元素賦初值0 for (i=0;i<ca;i+) for (j=0;j<cb;j+) si+j+1+=(ai-'

2、0')*(bj-'0'); for (i=ca+cb-1;i>=0;i-) / 這里實現(xiàn)進位操作 if (si>=10) si-1+=si/10; si%=10; i=0; while(si=0) i+; / 跳過頭部0元素 for (;i<ca+cb;i+) printf("%d",si); printf("n"); free(s);int main() char a100,b100; gets(a),gets(b); if(a0='-'&&b0!='-') pr

3、intf("-"); cheng(&a1,b); else if(a0='-'&&b0='-') cheng(&a1,&b1); else if(a0!='-'&&b0='-') printf("-"); cheng(a,&b1); else cheng(a,b); return 0;T072、創(chuàng)建與遍歷職工鏈表#include <stdio.h>#include <stdlib.h>struct mem

4、ber int data; struct member*next;struct member *creat(struct member*head) struct member *p1,*p2=NULL; int i,n; scanf("%d",&n); for(i=0;i<n;i+) p1=(struct member*)malloc(sizeof(struct member); scanf("%d",&p1->data); if(i=0) head=p1; else p2->next=p1; p2=p1; p2->

5、;next=NULL; return head;void list(struct member*head) struct member *p=head; while(p!=NULL) printf("%d ",p->data); p=p->next; printf("n");int main() struct member *head; head=creat(head); list(head); return 0;T073、幸運兒#include <stdio.h>int main() int a51=0,b20,x,count=

6、0,num=0,j=0,n,i,flag=0; scanf("%d%d",&n,&x); for(i=0;i<20;i+) scanf("%d",&bi); while(1) for(i=1;i<=n;i+) if(ai=0) num+; if(num=bj) ai=1; num=0; count+; if(count=n-x) flag=1; break; if(flag=1) break; j+; num=0; for(i=1;i<=n;i+) if(ai=0) printf("%d ",

7、i); printf("n"); return 0;T074、插入鏈表節(jié)點#include <stdio.h>#include <stdlib.h>struct member int data; struct member*next;struct member *creat(struct member*head) struct member *p1,*p2=NULL; int i,n; scanf("%d",&n); for(i=0;i<n;i+) p1=(struct member*)malloc(sizeof(s

8、truct member); scanf("%d",&p1->data); if(i=0) head=p1; else p2->next=p1; p2=p1; p2->next=NULL; return head;struct member *insert(struct member*head) struct member *p0=head,*p1; p1=(struct member *)malloc(sizeof(struct member); scanf("%d",&p1->data); while(p0-&

9、gt;next!=NULL) if(p0->data<p1->data&&p0->next->data>p1->data) p1->next=p0->next; p0->next=p1; p0=p0->next; return head;void list(struct member*head) struct member *p=head; while(p!=NULL) printf("%d ",p->data); p=p->next; printf("n");

10、int main() struct member *head; head=creat(head); head=insert(head); list(head); return 0;T075、畢業(yè)設計論文打印#include <stdio.h>int main() int n,m,a100=0,count=0,flag=0,i,j; scanf("%d%d",&n,&m); for(i=0;i<n;i+) scanf("%d",&ai); while(1) for(i=0;i<n&&ai!=0

11、;i+) for(j=i;j<n;j+) if(aj>ai) break; if(j=n) ai=0; count+; if(i=m) flag=1; break; if(flag=1) break; printf("%dn",count); return 0;T076、鏈表動態(tài)增長或縮短#include <stdio.h>#include <stdlib.h>#define LEN sizeof(struct student)int a10000;struct studentint age;struct student *next;in

12、t n;struct student *creat(int num) struct student *head; struct student *p1,*p2; n=0; p1=p2=(struct student*)malloc(LEN); scanf("%d",&p1->age); head=NULL; while(n<num) n=n+1; if(n=1) head=p1; else p2->next=p1; p2=p1; p1=(struct student *) malloc(LEN); if(n<num) scanf("

13、%d",&p1->age); p2->next=NULL; return head;struct student *del(struct student *head) struct student *p1,*p2,*p3,*p4,*p5; p1=head; p5=head; do if(ap1->age=1&&p1->next!=NULL) p2->next=p1->next; p3=p5; while(p3!=NULL) if(p3->age=p1->age) if(p3=head) head=p3->n

14、ext; else p4->next=p3->next; p4=p3; p3=p3->next; else if(ap1->age=1&&p1->next=NULL) p2->next=NULL; p3=p5; while(p3!=NULL) if(p3->age=p1->age) if(p3=head) head=p3->next; else p4->next=p3->next; p4=p3; p3=p3->next; else ap1->age=1; p2=p1; p1=p1->next;

15、while(p1!=NULL); return head;int main() int num; scanf("%d",&num); struct student *p; p=creat(num); p=del(p); do printf("%d ",p->age); p=p->next; while(p!=NULL); return 0;T077、大數(shù)減法#include <stdio.h>#include <string.h>#define max(a,b) a>b?a:b#define min(a,

16、b) a>b?b:aint sum101;void jia(char a,char b) int flag=0,i,len1,len2,lenmax,lenmin; len1=strlen(a),len2=strlen(b); lenmax=max(len1,len2),lenmin=min(len1,len2); for(i=1;i<=lenmax;i+) if(i<=lenmin) sumlenmax-i=alen1-i+blen2-i-'0'-'0'+flag; if(sumlenmax-i>=10) sumlenmax-i=sum

17、lenmax-i-10; flag=1; else flag=0; else if(len1>len2) sumlenmax-i=alen1-i-'0'+flag; if(sumlenmax-i>=10) sumlenmax-i=sumlenmax-i-10; flag=1; else flag=0; else sumlenmax-i=blen2-i-'0'+flag; if(sumlenmax-i>=10) sumlenmax-i=sumlenmax-i-10; flag=1; else flag=0; if(flag=1) printf(&

18、quot;1"); for(i=0;i<lenmax;i+) printf("%d",sumi); printf("n");void jian(char a,char b) int flag=0,i; int len1,len2; len1=strlen(a),len2=strlen(b); for(i=1;i<=len1;i+) if(i<=len2) if(alen1-i-blen2-i-flag>=0) sumlen1-i=alen1-i-blen2-i-flag; flag=0; else sumlen1-i=a

19、len1-i-blen2-i-flag+10; flag=1; else if(alen1-i-flag-'0'>=0) sumlen1-i=alen1-i-flag-'0' flag=0; else sumlen1-i=alen1-i-flag+10-'0' flag=1; for(i=0;i<len1&&sumi=0;i+); for(;i<len1;i+) printf("%d",sumi); printf("n");void compare(char a,char

20、b) int len1,len2; len1=strlen(a),len2=strlen(b); if(len1>len2|(len1=len2&&strcmp(a,b)>0) jian(a,b); else if(strcmp(a,b)!=0) printf("-"); jian(b,a); else printf("0n");int main() char a100,b100; gets(a); gets(b); if(a0='-'&&b0!='-') printf(&quo

21、t;-"); jia(&a1,b); else if(a0='-'&&b0='-') compare(&b1,&a1); else if(a0!='-'&&b0='-') jia(a,&b1); else compare(a,b); return 0;T078、大數(shù)除法#include<stdio.h>#include<string.h>int len1,len2;int re105;void sub(char s1,char s2)

22、 int i=0; int j; while(1) if(s1i='0') i+; else j=i; break; for(;i<len2;i+) s1i=s1i-s2i+'0' for(i=len2-1;i>j;i-) /低位開始檢測是否小于0 if(s1i<'0') s1i+=10; s1i-1-; void chu(char s1,char s2) int p,i; len1=strlen(s1); len2=strlen(s2); if(len1<len2|(len1=len2&&strncmp(

23、s1,s2,len2)<0) /如果a<b,直接輸出0 printf("0n"); return; p=0; while(1) rep=0; while(strncmp(s1,s2,len2)>=0) /一直進行減法,直到不能減為止 sub(s1,s2); rep+; p+; if(len1=len2) break; for(i=len2-1;i>=0;i-) /在s2前面補0,以便進行減法運算 s2i+1=s2i; s20='0' len2+; s2len2='0' i=0; while(1) if(rei=0) i

24、+; else break; for(;i<p;i+) printf("%d",rei); printf("n");int main(void) char s1105; char s2105; gets(s1),gets(s2); if(s10='-'&&s20!='-') printf("-"); chu(&s11,s2); else if(s10='-'&&s20='-') chu(&s11,&s21);

25、else if(s10!='-'&&s20='-') printf("-"); chu(s1,&s21); else chu(s1,s2); return 0;T079、鏈表節(jié)點刪除#include <stdio.h>#include <stdlib.h>struct student int no; char name12; int age; struct student *next;struct student *deletelist(struct student *head,int n) s

26、truct student *p=head,*q; if(p->no=n) head=p->next; free(p); else while(p->next!=NULL&p->next->no!=n) p=p->next; if(p->next->no=n) q=p->next; p->next=q->next; free(q); return head;void list(struct student *head) struct student *p=head; while(p->next!=NULL) pri

27、ntf("%d ",p->no); p=p->next; printf("n");int main() int n,i=0; struct student *head,*p1,*p2; p1=p2=(struct student *)malloc(sizeof(struct student); for(i=0;i+) if(i=0) head=p1; else p2->next=p1; p2=p1; scanf("%d",&p1->no); if(p1->no=0) break; scanf("%

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論