Skip to content

Commit

Permalink
Merge A,B course
Browse files Browse the repository at this point in the history
  • Loading branch information
heqin-zhu committed Nov 14, 2018
1 parent 98a6fe8 commit 6ed57c3
Show file tree
Hide file tree
Showing 411 changed files with 12,513 additions and 0 deletions.
Binary file not shown.
3 changes: 3 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
页数与题号参照 父目录中的 [C程序设计(第四版)].谭浩强.扫描版.pdf

由于免修考试结果到了期中才出, 所以写的lab 只到期中 /衰
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p112_10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<math.h>

int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
printf("输入奖金: ");
int n;
scanf("%d",&n);
if(n<=1e5)printf("%.2f",n*0.1);
else if(n<=2e5)printf("%.2f",1e4+(n-1e5)*0.075);
else if(n<=4e5)printf("%.2f",1e4+7500+(n-2e5)*0.05);
else if(n<=6e5)printf("%.2f",1e4+7500+10000+(n-4e5)*0.015);
else printf("%.2f",1e4+7500+10000+6000+(n-6e5)*0.01);
return 0;
}

29 changes: 29 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p112_11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stdio.h>
#include<math.h>
void sort(int n,int *arr)
{
for(int i=0;i<n-1;++i){
for(int j=0;j<n-i-1;++j){
if(arr[j]>arr[j+1]){
int tmp=arr[j];
arr[j] = arr[j+1];
arr[j+1]= tmp;
}
}
}
}
int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
printf("input n: ");
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)scanf("%d",a+i);
sort(n,a);
for(int i=0;i<n;i++)printf("%d ",a[i]);
printf("\n\n");
return 0;
}


22 changes: 22 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p112_12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
#include<math.h>
int notIn(float x,float y,int r)
{
if((x+2)*(x+2)+(y-2)*(y-2)<=r*r)return 0;
if((x-2)*(x-2)+(y-2)*(y-2)<=r*r)return 0;
if((x+2)*(x+2)+(y+2)*(y+2)<=r*r)return 0;
if((x-2)*(x-2)+(y+2)*(y+2)<=r*r)return 0;
return 1;
}

int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
printf("输入坐标, 以空格分开: ");
float x,y;
scanf("%f %f",&x,&y);
if(!notIn(x,y,1)) printf("10m\n");
else printf("0m\n");
return 0;
}

17 changes: 17 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p112_6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<math.h>

int f(int x)
{
if(x<1)return x;
else if(x<10) return 2*x-1;
else return 3*x-11;
}
int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
int xs[]={0,5,10};
for(int i=0;i<3;++i) printf("x=%d, y=%d\n",xs[i],f(xs[i]));
return 0;
}

20 changes: 20 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p112_8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
#include<math.h>

char score(int n)
{
if(n>=90)return 'A';
else if (n>=80)return 'B';
else if (n>=70)return 'C';
else if (n>=60)return 'D';
else return 'E';
}
int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
int ns[]={56,66,76,86,96};
for(int i=0;i<5;++i)
printf("分数:%d 成绩: %c\n",ns[i],score(ns[i]));
return 0;
}

22 changes: 22 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p112_9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
#include<math.h>
int digit(int n)
{
int ct=0;
do{
printf("%d",n%10);
n/=10;
ct +=1;
}while(n);
printf("共%d 位数字\n",ct);
return ct;
}

int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
digit(8650);

return 0;
}

32 changes: 32 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p82_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>
#include<math.h>
double ratio[]={0.0414,0.0468,0.054,0.054,0.0585};

double dingqi(double money,int n,int *years)
{
double rst = money;
for(int i=0;i<n;++i){
rst *=(1+years[i] * ratio[years[i]]);
}
return rst;
}

double huoqi_ratio=0.0072;
double huoqi(double money,int n)
{
return money*pow((1+huoqi_ratio),4*n);
}

int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
double money = 1000;
int a[]={5},b[]={2,3},c[]={3,2},d[]={1,1,1,1,1};
printf("第一种: %.4lf\n",dingqi(money,1,a));
printf("第二种: %.4lf\n",dingqi(money,2,b));
printf("第三种: %.4lf\n",dingqi(money,2,c));
printf("第四种: %.4lf\n",dingqi(money,5,d));
printf("第五种: %.4lf\n",huoqi(money,5));
printf("----------------\n\n");
return 0;
}
13 changes: 13 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p82_3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include<stdio.h>
#include<math.h>

int main(int argc,char **argv)
{
printf("%s\n",argv[0]);
int d =3e5, p=6e3;
float r=0.01;
float m = log10(p/(p-d*r))/log10(1+r);
printf("需 %.1f个月还清\n",m+0.05);
printf("----------------\n\n");
return 0;
}
24 changes: 24 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab1/p82_6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>

char encrypt(char c)
{
c = c+4;
if(( c<'a'&&c>'Z') || c>'z') c-=26;
return c;
}
int main(int argc,char **argv)
{
printf("%s\n",argv[0]);

char c[] = {'C','h','i','n','a'};
printf("putchar: ");
for(int i=0;c[i]!='\0';++i){
c[i]=encrypt(c[i]);
putchar(c[i]);
}

printf("\nprintf: %s\n",c);
printf("----------\n\n");
return 0;
}

Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab2/p140_12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include<stdio.h>
int main()
{
int i=10,num=1;
for(;i>1;i--)num = (num+1)*2;
printf("第一天的桃子数: %d",num);
return 0;
}
58 changes: 58 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab2/p140_17.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include<stdio.h>

//使用康托展开计算全排列, 下面存储的是0!,1!,2!...(n-1)!
long long int fac[100]={};
void calFac(int n)
{
int i;
fac[0]=1;
for(i=1;i<=n;i++){
fac[i]=i*fac[i-1];
}
}

/* 思路是, 设置一个数组, 索引编号分别对应 甲 队的成员A,B,C... , 数组的值对应 乙队的成员 X,Y,Z...*/
void getArrangement(int *arr,int n,int sum)
{
/*从整数 sum 得到一个 n位的排列存储到 arr 中*/
int i,j,ct=0,k, ct2;
int flag[n];
for(i=0;i<n;i++)flag[i]=1;

for(i=n-1;i>=0;i--){
for(j=i;j>=0;j--){
if(j*fac[i]<=sum){
ct2=0;
for(k=0;k<n;++k){
//printf("i%d j%d k%d\n",i,j,k);
if(flag[k]==1)ct2++;
if(ct2>j)break;
}
arr[ct++] = k;
flag[k]=0;
sum -=j*fac[i];
break;
}
}
}
}

void nextArrangement(int *arr, int n)
{//todo
}
int main(int argc,char **argv)
{
int n=6, arr[n],i;
long long int f=0;
calFac(n);
for(f=0;f<fac[n];++f){
getArrangement(arr,n,f);
if(arr[0]!=0 && arr[2]!=0 &&arr[2]!=2)break;
}
printf("给甲乙队编号 0,1,2...\n");
printf("甲队: ");
for(i=0;i<n;i++)printf("%d ",i);
printf("\n乙队: ");
for(i=0;i<n;i++)printf("%d ",arr[i]);
return 0;
}
25 changes: 25 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab2/p140_4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<stdio.h>

void count(char * s)
{
int en=0,space=0,num=0,other=0;
int i=0;
while(s[i]!='\0'&&s[i]!='\n'){
if( s[i]<='9' && s[i]>='0') num++;
else if (s[i]==' ') space++;
else if ((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')) en++;
else other++;
i++;
}
printf("alpha: %d\nnumber: %d\nspace: %d\nother: %d\n",en,num,space,other);
}

int main()
{
int n= 1000;
printf("input a string: ");
char s[n];
fgets(s,n,stdin);
count(s);
return 0;
}
14 changes: 14 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab2/p140_5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
#include<math.h>
int main()
{
int a,n;
printf("input a: ");
scanf("%d",&a);
printf("input n: ");
scanf("%d",&n);
long long int s = 0;
s = a*((2*pow(10,n+1)-20-9*n*(n+1))/2/81);
printf("result is : %lld", s);
return 0;
}
19 changes: 19 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab2/p140_8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
#include<math.h>

int main()
{
int i=0, a,b,c,ct=0;
printf("所有水仙花数: \n");
for(i=100;i<1000;++i){
a = i/100;
b=i%100 /10;
c=i%10;
if(pow(a,3)+pow(b,3)+pow(c,3)==i){
printf("%d, ",i);
ct+=1;
if(ct%8==0)printf("\n");
}
}
return 0;
}
18 changes: 18 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab2/p140_9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
int facSum(int n)
{
int i,s=0;
if(n==0)return 0;
for(i=1;i<=n/2;i++){
if(n%i==0)s+=i;
}
return s;
}
int main()
{
int i=6,n=1000;
printf("%d 以内的完全数",n);
for(;i<n;i++)
if(facSum(i)==i)printf("%d ",i);
return 0;
}
Binary file not shown.
Empty file.
Binary file not shown.
19 changes: 19 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab3/p168_1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
#define MAX 1<<15
int primes[MAX];
void findPrime(int max)
{
int i,j;
for(i=2;i<=max;++i) primes[i] = 1;
for(i=2;i<max;++i)
for(j=i+1;j<=max;++j) if(primes[j]==1 && j%i==0)primes[j]=0;
printf("primes below %d are:\n",max);
for(i=2;i<=max;++i)if(primes[i]==1)printf("%d ",i);
printf("\n");
}

int main()
{
findPrime(100);
return 0;
}
Binary file not shown.
19 changes: 19 additions & 0 deletions 计算机与信息类/c&c++/程序设计lab/lab3/p168_13.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>

void concat(char s1[],char s2[])
{
int i=0,j=0;
while(s1[i])++i;
while(s1[i++]=s2[j++]);
}

int main()
{
char s1[1000] = "hello";
char s2[] = ", world";
printf("s1: %s\ns2: %s\n",s1,s2);
concat(s1,s2);
printf("连接后: \n%s",s1);
return 0;
}

Binary file not shown.
Loading

0 comments on commit 6ed57c3

Please sign in to comment.