​​推荐:NEFU大一下C语言锐格实验与作业参考程序目录​​

文章目录

  • ​​NEFU锐格实验一[字符串]​​
  • ​​知识点​​
  • ​​题解​​
  • ​​5807​​
  • ​​5813​​
  • ​​5810​​
  • ​​5811​​
  • ​​5812​​

NEFU锐格实验一[字符串]

知识点

题目

知识点

5807

大小写转换

5813

字母转换

5810

压缩连续01

5811

取模运算

5812

题解

5807

#include <stdio.h>
#include <stdlib.h>
#define LEN 10
int main()
{
char array[LEN];
int i;
gets(array);
i=0;
while(array[i]!='\0')
{
//start
if(array[i]>='A'&&array[i]<='Z')array[i]=array[i]-'A'+'a';
++i;
//end
}
printf("%s",array);
return 0;
}

5813

#include <stdio.h>
#include <stdlib.h>
#define LEN 100
int main(void)
{
char one[LEN],the_other[LEN]; //one用于存储原串;the_other用于存储匹配串
int i,j;
gets(one);
i=0, j=0;
while(one[i]!='\0')
{
//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';
else the_other[i]=one[j];
++i;++j;
//end
}
the_other[j] = '\0';
puts(the_other);
return 0;
}

5810

#include <stdio.h>
#include <stdlib.h>
#define LEN 100
int main()
{
int compress(char array[], int count[]);
char array[LEN];
int count[LEN];
int i;
int tail; //count数组的有效最末下标
while(scanf("%s",array)!=-1)
{
tail = compress(array, count);
for(i=0;i<tail;i++)
i<tail-1 ? printf("%d ",count[i]) : printf("%d\n",count[i]);
}
return 0;
}
int compress(char array[], int count[])
{
//start
int len=0,cnt=0,flag=0; //flag标记状态
for(int i=0;array[i];i++)
{
if((array[i]-'0'+flag)%2)//数与状态不同奇偶更新,比如状态为0现在数为1就要更新
{
flag=flag?0:1;
count[len++]=cnt;
cnt=1;
}
else cnt++;
}
count[len++]=cnt;//不要忘记结尾更新
return len;
//end
}

5811

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 81
int main()
{
void Caesar_transform(char message[], int shift);
char message[LEN];
int shift;
printf("Enter message to be encrypted: ");
gets(message);
printf("Enter shift amount (1-25): ");
scanf("%d",&shift);
printf("Encrypted message: ");
Caesar_transform(message, shift);
printf("%s\n",message);
return 0;
}
void Caesar_transform(char message[], int shift)
{
//start
for(int i=0;message[i];i++)
if(message[i]>='A'&&message[i]<='Z')
message[i]=(message[i]-'A'+shift)%26+'A';
else if(message[i]>='a'&&message[i]<='z')
message[i]=(message[i]-'a'+shift)%26+'a';
//end
}

5812

挺迷惑的一题哦
PE格式错误的,不知道死哪里了
码了,等开学了再说

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
#define LEN 100
char s[N][LEN];//存储
char input[LEN];//输入
int main()
{
int cnt=0;
char last;//标记最后的符号
printf("Enter a sentence: ");
while(scanf("%s",input)!=EOF)
strcpy(s[++cnt],input);
int len=strlen(s[cnt]);
last=s[cnt][len-1];
s[cnt][len-1]='\0';
printf("Reversal of sentence:");
for(int i=cnt;i>=1;i--)printf(" %s",s[i]);
printf("%c\n",last);
return 0;
}

目前的解决办法是开F12复制粘贴!直接输出嘻嘻

#include<stdio.h>

int main()
{
printf("Enter a sentence: Reversal of sentence: you can't swallow a cage can you? ");
}

顺便c++打习惯的同学建议把const改成define吧

NEFU锐格实验一[字符串]_i++