5807 大小写转换
#include <stdio.h>
#include <stdlib.h>
#define LEN 10
int main()
{
char array[LEN],b[10];
int i;
gets(array);
i=0;
while(array[i]!='\0')
{
//start
if(array[i]>='A'&&array[i]<='Z')
{
array[i]=array[i]+32;
}
if(i<LEN)
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
the_other[j]= one[i];
if(one[i]=='A')
{
the_other[j]='T';
}
if(one[i]=='T')
{
the_other[j]='A';
}
if(one[i]=='G')
{
the_other[j]='C';
}
if(one[i]=='C')
{
the_other[j]='G';
}
if(i<LEN)
i++;
if(j<LEN)
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 k=1,j=0;
char f;
for(int i=0;i<LEN;i++)
{
count[i]=0;
}
int i=0;
f=array[0];
while(array[i]!='\0')
{
if(f==array[i])
{
count[j]++;
}
else
{
j++;
count[j]++;
f=array[i];
}
i++;
}
return j+1;
//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)
{
//starts
for(int i=0;i<LEN;i++)
{
if(message[i]>='a'&&message[i]<='z')
if(message[i]+shift>'z')
message[i]=message[i]-26+shift;
else message[i]=message[i]+shift;
if(message[i]>='A'&&message[i]<='Z')
if(message[i]+shift>'Z')
message[i]=message[i]-26+shift;
else message[i]=message[i]+shift;
}
//end
}