NEFU锐格实验一[字符串]

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

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吧
在这里插入图片描述

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值