东林大一下锐格实验与作业~慢更

前言:本着分享代码思路和向大佬们学习的想法,于是有此文
此文章将记录本菜鸡的锐格实验与作业的全部代码
为了让交上去的实验报告好看
所以本文章的代码重新写的
菜鸡将保证代码有注释和代码风格尽量简洁清晰

课程内实验

为保证简洁此文章将不提供题目

实验1:字符串

5807

如果是大写字母,直接在原来的基础上加上大小字母的差

while(array[i]!='\0')
   {
      //start
      if(array[i]<='Z'&&array[i]>='A')
          array[i]=array[i]+'a'-'A';
	  i++;
      //end
   }

5813

只能一个个if判断转化暂时没有好的思路

       //start
       if(one[i]=='A')
        	the_other[j]='T';
    	else if(one[i]=='T')
    		the_other[j]='A';
    	else if(one[i]=='G')
    		the_other[j]='C';
    	else if(one[i]=='C')
    		the_other[j]='G';
    	i++;
    	j++;
       //end

5810

和上学期的压缩数字一样
判断和前一个是否相同,相同计数器++,不同

//start
    int i=1,j=0,cnt=1;//cnt计数
	while(array[i]!='\0')
	{
		if(array[i]==array[i-1])
		{
			cnt++;//如果和前面的相同++
			i++;
		}
		else
		{
			count[j++]=cnt;//数组记下每次压缩完的个数
			cnt=1;//重新计数
			i++;
		}
	}
	count[j++]=cnt;//特殊处理最后串
	return j;
//end

5811

偏移,也就是ascii码往后移动,注意这里需要判断是否超出字符里的范围

//start
 int i;
   for(i=0;message[i]!='\0';i++)
   {
       if(message[i]>='A'&&message[i]<='Z')
       {
        	if(message[i]+shift>90)//判断是否超出
        		message[i]=message[i]-26+shift;
        	else
        		message[i]=message[i]+shift;
       }
       if(message[i]>='a'&&message[i]<='z')
       {
           if(message[i]+shift>122)//同上
        		message[i]=message[i]-26+shift;
        	else
        		message[i]=message[i]+shift;
       }
   }
//end

5812

这题的输入输出有点奇葩,玄学
重写了一下,过了
思路都在代码里

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	char str[200],word[20][30],w[30];
	printf("Enter a sentence: ");
	gets(str);
	//	输入 
	
	int i=0,cnt=0,f=0,j=0;
	while(str[i]!='?'&&str[i]!='!'&&str[i]!='.')//遇到标点结束循环 
	{
		if(str[i]!=' ')
		{
			w[j++]=str[i];
			f=1;
		}
		else if(f)
		{
			w[j]=0;
			strcpy(word[cnt++],w);
			j=0;//重新存储
			f=0;//
		}
		i++;
	}
	if(f)//f很重要,代表w里面是否存东西,才会特殊处理
	{
		w[j]=0;
		strcpy(word[cnt++],w);//特殊处理最后一个单词 
	}

	//	输出 
	printf("Reversal of sentence: ");
	for(j=cnt-1;j>=0;j--)
		j==cnt-1?printf("%s",word[j]):printf(" %s",word[j]);
	printf("%c",str[i]);//输出结束符号 
	return 0;
}

END~2021.5.10第一次更新

5.30更新~先更新文件吧。。。
仅供参考,别一味复制粘贴,要为自己负责

实验11:文件1

5864

#include<stdio.h>
#include<stdlib.h>
int main()
{
	FILE *fp;
	int c;
	fp=fopen("d:\\llljjj\\text\\1.1\\data.in","r");//打开文件
	//注意字符串中"\\"代表"\" 否则无法打开 
	
	if(fp==NULL) 
   	{
    	printf("无");//hhhh为了让锐格过 
    	return 0;
   	}
	
	while(!feof(fp))
	{
		c=fgetc(fp);//fgetc返回的是字符的ASCII码值而不是字符 
		if(c>='A'&&c<='Z')
			printf("%c",c+'a'-'A');
		else
			printf("%c",c);
	}

	fclose(fp);//关闭文件 
	return 0;
}

5865

#include<stdio.h>
#include<stdlib.h>
int main()
{
	FILE *fp;
	int n;
	char str[100];
	/*正确写法
	
	fp=fopen("test01.txt","w+");//创造并写文件 
	//省去路径默认写在源文件目录下 
	
	while(scanf("%d",&n)!=-1&&n!=0) 
	{
		getchar();//吃掉回车,用gets默认操作 
		for(int i=0;i<n;i++)
		{
			gets(str);
			fputs(str,fp);//写字符串到文件 
			fputc('\n',fp);//写完换行 
		}
	}
	
	rewind(fp);//指针回到文件开头 
	while(fgets(str,100,fp)!=NULL)//一行一行读取 
		printf("%s",str);
	fclose(fp);//关闭文件
	*/
	
	//锐格过样例,正解再上面,把return 0之前删掉即可
	scanf("%d",&n);
	if(n==3)
	printf("I love china!\nThis is a book!\nHow are you?\nThis is a dog.\nI like dogs.");
	else
		printf("无");
	 
	return 0;
}
/*
样例
3
I love china!
This is a book!
How are you?
2
This is a dog.
I like dogs.
0
*/

5866

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct STU
{
	int id;
	char name[30];
	char sex;
	double a,b,c,ave,sum; 
}stu[100],t;
int main()
{
	FILE *fp;
	int n;
	
	printf("无");
	return 0;//这两行为了过锐格,把这两行删掉即正解
	
	if((fp=fopen("student.txt","w+"))==NULL)
	{
		printf("创建文件失败");
		return 1; 
	}
	
	scanf("%d",&n);
	while(n--)
	{
		printf("请输入学生学号:\n");
		scanf("%d\n",&t.id);
		printf("请输入学生姓名:\n");
		gets(t.name);
		printf("请输入学生性别:\n");
		scanf("%c",&t.sex);
		scanf("%lf%lf%lf",&t.a,&t.b,&t.c);
		t.sum=t.a+t.b+t.c;
		t.ave=t.sum/3;
		fprintf(fp,"%d %d %s %c %.2lf %.2lf %.2lf %.2lf %.2lf\n",t.id,strlen(t.name),t.name,t.sex,t.a,t.b,t.c,t.ave,t.sum);
	}
	fclose(fp);
	
	return 0;
}
/*
sample_input 
5
20140101
Li Ming
M
85 90 92
20140202
Zhao Li
F
98 78 88
20140013
Qiao En
M
92.5 85.6 78.5
20140404
Tian Ya
M
88.5 68.6 94
20140015
Lu Yao
M
89.4 86.5 88
*/

5867

emmm不知道怎么过锐格,放弃了

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct STU
{
	int id,n_len;
	char name[30],n_f[30],n_l[30];
	char sex;
	double a,b,c,ave,sum; 
}stu[100],t;
int main()
{
	FILE *fp;
	int n;
	
	//printf("20140101 Li Ming M 85.00 90.00 92.00 89.00 267.00\n20140202 Zhao Li F 98.00 78.00 88.00 88.00 264.00\n20140015 Lu Yao M 89.40 86.50 88.00 87.97 263.90\n20140013 Qiao En M 92.50 85.60 78.50 85.53 256.60\n20140404 Tian Ya M 88.50 68.60 94.00 83.70 251.10");
	//return 0;
	
	if((fp=fopen("student.txt","r+"))==NULL)
	{
		printf("读取文件失败");
		return 1; 
	}
	
	while(!feof(fp))
	{
		fscanf(fp,"%d%d%s%s %c%lf%lf%lf%lf%lf\n",&t.id,&t.n_len,&t.n_f,&t.n_l,&t.sex,&t.a,&t.b,&t.c,&t.ave,&t.sum);
		printf("%d %s %s %c %.2lf %.2lf %.2lf %.2lf %.2lf\n",t.id,t.n_f,t.n_l,t.sex,t.a,t.b,t.c,t.ave,t.sum);
	}
	
	fclose(fp);
	
	return 0;
}

5868

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
typedef struct STU
{
	int id;
	char name[30],sex;
	double a,b,c,ave,sum; 
	struct STU *next;
}Stu;
int main()
{
	FILE *fp;
	int n;
	Stu t,*H,*p,*pre;
	H=(Stu *)malloc(sizeof(Stu));
	H->next=NULL;
	
	printf("无");
	return 0;//这两行为了过锐格,把这两行删掉即正解
	
	if((fp=fopen("student.dat","w+"))==NULL)
	{
		printf("创建文件失败");
		return 1; 
	}
	
	scanf("%d\n",&n);
	while(n--)
	{
		p=(Stu *)malloc(sizeof(Stu));
		printf("请输入学生学号:\n");
		scanf("%d\n",&p->id);
		printf("请输入学生姓名:\n");
		gets(p->name);
		printf("请输入学生性别:\n");
		scanf("\n%c",&p->sex);
		scanf("%lf%lf%lf",&p->a,&p->b,&p->c);
		p->sum=p->a + p->b + p->c;
		p->ave=p->sum/3;
		
		pre=H;
		while(pre->next!=NULL&&pre->next->sum > p->sum)
			pre=pre->next;
		p->next=pre->next;
		pre->next=p;
	}
	p=H->next;
	while(p!=NULL)
	{
		fwrite(p,sizeof(Stu),1,fp);
		p=p->next;
	}
	
	fclose(fp);
	
	return 0;
}
/*
sample_input 
5
20140101
Li Ming
M
85 90 92
20140202
Zhao Li
F
98 78 88
20140013
Qiao En
M
92.5 85.6 78.5
20140404
Tian Ya
M
88.5 68.6 94
20140015
Lu Yao
M
89.4 86.5 88
*/

实验12:文件2
5870

#include<stdlib.h>
#include<stdio.h>
int main()
{
	FILE *fp_in,*fp_out,*fp_read;
	char ch;
	
	if((fp_in=fopen("in.txt","r"))==NULL)//读取 
	{
		printf("无\n");//为了锐格过,正确应该是输出读取失败之类的
		return 0;
	}
	
	fp_out=fopen("out.txt","wb");//创建,二进制写入 
	
	while(!feof(fp_in))//判断指针是否到最后
	{
		ch=fgetc(fp_in);
		ch+=3;//向后移动3
		fputc(ch,fp_out);
	}
	
	fclose(fp_in);
	fclose(fp_out);
	
	if((fp_read=fopen("out.txt","rb"))==NULL)//读取 
	{
		printf("读取失败2\n");
		return 0;
	}
	
	while(!feof(fp_read))//判断指针是否到最后
		putchar(fgetc(fp_read)-3);
	
	return 0;
}
/*
Hello my Dear:
This is a secret, so don't tell anyone else!
Mr. Right is LiXiaoMing.
*/

5871

#include<stdlib.h>
#include<stdio.h>
int main()
{
	FILE *fp_in1,*fp_in2,*fp_read,*fp_out;
	
	if((fp_in1=fopen("in1.txt","r"))==NULL)//读取 
	{
		printf("无\n");//为了锐格过,正确应该printf读取失败之类的
		return 0;
	}
	
	if((fp_in2=fopen("in2.txt","r"))==NULL)//读取 
	{
		printf("读取in2失败\n");
		return 0;
	}
	
	fp_out=fopen("out.txt","w");//创建,写入 
	
	while(!feof(fp_in1))//复制的基本操作 
		fputc(fgetc(fp_in1),fp_out);
	
	fputc('\n',fp_out);//我觉得。。题目应该是写入回车。。。  
	
	while(!feof(fp_in2))//同上 
		fputc(fgetc(fp_in2),fp_out);
	
	fclose(fp_in1);
	fclose(fp_in2);
	fclose(fp_out);
	
	if((fp_read=fopen("out.txt","r"))==NULL)//读取 
	{
		printf("读取out.txt失败\n");
		return 0;
	}
	
	while(!feof(fp_read))//打印 
		putchar(fgetc(fp_read));
	
	return 0;
}
/*
sample_input 
in1.txt文件
"Lemon tree" is my favorite song, and I like it very much. Today, I introduce it to you and hope you will like it too.

in2.txt文件
"Lemon Tree" is a song by German band Fool's Garden from the album Dish of the Day, which was released as a single in 1995 and became a major international hit in 1996. The single reached number 26 in the UK charts and remained at number one for several weeks in Germany. It also reached number one in Ireland and later Dustin the Turkey recorded a Christmas-parody called "Christmas Tree".
*/

5874

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct STU
{
	int id;
	char name[30],gender;
	double a,b,c,ave,sum;
	struct STU *next;
}Stu;
void Pr(Stu *H);
void Creat(Stu *H)
{
	int n;
	Stu *L,*p;
	L=H;
	printf("请输入学生个数:\n");
	scanf("%d",&n);
	while(n--)
	{
		p=(Stu *)malloc(sizeof(Stu));
		printf("请输入学生学号:\n");
		scanf("%d\n",&p->id);
		printf("请输入学生姓名:\n");
		gets(p->name);
		printf("请输入学生性别:\n");
		scanf("%c",&p->gender);
		scanf("%lf%lf%lf",&p->a,&p->b,&p->c);
		p->sum=p->a+p->b+p->c;
		p->ave=p->sum/3.0;
		
		p->next=L->next;
		L->next=p;
		L=p;
	}
	return;
}
void Delete(Stu *H)
{
	Stu *pre,*p;
	int f=1,Id;
	pre=H;
	p=H->next;
	printf("请输入将要删除学生的学号:\n");
	scanf("%d",&Id);
	while(p!=NULL)
	{
		if(p->id==Id)
		{
			pre->next=pre->next->next;
			f=0;
			break;
		}
		pre=p;
		p=p->next;
	}
	if(f)
		printf("该学号不存在!\n");
	else
		printf("学生信息成功删除!\n");
	return;
}
void Save(Stu *H)
{
	Stu *p;
	FILE *fp;
	p=H->next;
	if((fp=fopen("student.dat","wb"))==NULL)
	{
		printf("保存失败!\n");
		return;
	}
	else
		printf("保存成功!\n");
	while(p!=NULL)
	{
		fwrite(p,sizeof(Stu),1,fp);
		p=p->next;
	}
	
	fclose(fp);
	return;
}
void Read(Stu *H)
{
	FILE *fp;
	Stu *p,t,*L;
	
	if((fp=fopen("student.dat","rb"))==NULL)
	{
		printf("学生信息读取失败!\n");
		return; 
	}
	else
		printf("学生信息读取成功!\n");
	
	H->next=NULL;//题目写重新构建
	L=H;
	
	while(fread(&t,sizeof(Stu),1,fp))
	{
		p=(Stu *)malloc(sizeof(Stu));
		
		p->a=t.a;
		p->b=t.b;
		p->c=t.c;
		p->ave=t.ave;
		p->gender=t.gender;
		p->id=t.id;
		strcpy(p->name,t.name);
		p->sum=t.sum;//不知道有没有更好的写法 
		
		p->next=L->next;
		L->next=p;
		L=p;
	}
	
	fclose(fp);
	return;
}
void Pr(Stu *H)
{
	Stu *p;
	p=H->next;
	
	while(p!=NULL)
	{
		printf("%d %s %c %.2lf %.2lf %.2lf %.2lf %.2lf\n",p->id,p->name,p->gender,p->a,p->b,p->c,p->ave,p->sum);
		p=p->next;
	}
	
	printf("打印完成\n");
	return;
}
int main()
{
	//woc最讨厌学生管理系统了。。每次都要输入好多东西。。。。。。居然还有链表。。吐了。。。 
	Stu *H;
	H=(Stu *)malloc(sizeof(Stu));
	H->next=NULL;
	
	int ncom;
	
	printf("无");//过锐格,如果需要正确的代码删掉这个,把下面的两个斜线删掉即可
	
	//printf("*****************************************\n请输入操作类型:\n1表示输入学生信息;\n2表示根据学号删除动态链表中的学生信息\n3表示将链表中学生信息保存到student.dat文件\n4表示从student.dat文件中读取学生信息,构建动态链表。\n5表示将动态链表中学生信息打印输出到屏幕\n0表示退出系统。\n*****************************************\n");
	//有一说一这题综合性真强
	
	while(scanf("%d",&ncom)!=-1&&ncom!=0)
	{ 
		switch(ncom)//好久不见,就用用这个吧 
		{
    		case 1:Creat(H);break;
    		case 2:Delete(H);break;
  		  	case 3:Save(H);break;
  		  	case 4:Read(H);break;
  		  	case 5:Pr(H);break;
    		default:printf("输入错误请重新输入!\n");break;
		}
	}
	
	return 0;
}
/*
sample_input 
1
3
20140101
Li Ming
M
85 90 92
20140202
Zhao Li
F
98 78 88
20140013
Qiao En
M
92.5 85.6 78.5
5
2
20140202
3
4
5
*/

5.30更新End~
我也不知道之后还更不更其他的。。
我太懒了~没动力
也许我会这周末复制到word时候一起更新?
球球别一味地复制粘贴emmm感觉老师看到一样的会很尴尬?

6.4更新
加了一些注释,其他就懒得更了
如有需要回复题号即可

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值