东北林业大学锐格系统大一第二学期测试题(实验系列--字符串系列)

愿你如愿成光芒

最近小张同学深受打击,很是不愿意学习,但是,不可以这样啊!!!!!实验室的人实验室的人都太厉害了!!!!你要努力!!!!!
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]<='Z'&&array[i]>='A')
      {
          array[i]+=32;
      }
      i++;
    //end
   }
   printf("%s",array);
   return 0;
}

大写字母变成小写字母需要加32

在这里插入图片描述

#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[i]='T';
      if(one[i]=='T')
          the_other[i]='A';
      if(one[i]=='C')
          the_other[i]='G';
      if(one[i]=='G')
          the_other[i]='C';
          i++;
          j=i;
       //end
    }
    the_other[j] = '\0';
    puts(the_other);
    return 0;
}

在这里插入图片描述

#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 flag=1;int m=0;int i;
    if(strlen(array)==1) count[m++]=1;
    for(i=0;i<strlen(array);i++)
    {
       if(array[i]!=array[i+1])
        {
            count[m++]=flag;flag=0;

        }
        flag++;
        if(i==strlen(array)-1)
        {
            count[m++]=flag;
        }
    }
    return m;
//end
}

感觉这个题不难,但是有压缩的算法,但一看就知道是最简单的,需要熟练掌握
还有就是,需要判断长度大小如果只有一个,或者运行到最后一个无法和下一个比较的情况

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
   char a[100], ch;
   int i=0, word=0,f=1;
   printf("Enter a sentence: ");
   i=0;
   while(1)
   {
       a[i]=getchar();
       if(a[i]=='?'||a[i]=='!'||a[i]=='.')
         {ch=a[i];break;}
       if(a[i]!=' ' && f==1)
        { word++;f=0;}
       if(a[i]==' ' && f==0)
         f=1;
       i++;
   }
   ch=a[i];
   a[i]='\0';
   printf("Reversal of sentence: ");
   f = 0;
   while(i!=-1)
   {
       if(a[i]==' '||a[i]=='\0')
       {
           a[i]='\0';
           if(f==1)
           {
               f = 0;
               if(word>1)
                  printf("%s ",a+i+1);
               else
                  printf("%s",a+i+1);
               word--;
           }
       }
       else
       {
           if(f==0)
              f = 1;
       }
       if(i==0 &&  a[i]!='\0')
       printf("%s",a);
       i--;
   }
   printf("%c\n",ch);
   return 0;
}

算法很重要,今天有点晚了,明天看看然后开始指针,好了,晚安,未完待续

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值