目录
5766 字符插入并排序
5767 字符替换
5786 字符删除
5794 字符串拷贝
5796 字符串的连接
5795 字符串比大小
7124 字符串出现次数
7089 字符串中字母及个数
5810 数据压缩储存
5582 整数逆序数
5812 句子单词逆序输出
7165 句子中最长单词
5807 大写变小写
5813 碱基序列配对
8511 凯撒加密
5635 回文数字
5578 判断一个是另一个的倍数
5715 折半查找
5789 把前m个数放后面
5790 交换数组中的最大最小值
5791 冒泡排序
5432 求最小公倍数
5387 求最大公约数
5355 剪刀石头布
7175 (万能)十进制变十八进制
ps.比较简单的一道,字符串循环。
#include
#include
#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]+32;
i++;
}
else
i++;
//end
}
printf("%s",array);
return 0;
}
#include
#include
#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';
if(one[i]=='T')
the_other[j]='A';
if(one[i]=='C')
the_other[j]='G';
if(one[i]=='G')
the_other[j]='C';
i++;j++;
//end
}
the_other[j] = '\0';
puts(the_other);
return 0;
}
ps.这道比较难处理(若有更好方法欢迎指导)
#include
#include
#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
#include
#include
#include
#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
int i;
for(i=0;message[i]!='\0';i++)
{
if(message[i]>='a'&&message[i]<='z')
message[i]=(message[i]+shift-'a')%26+'a'; //对于'a'先减后加
if(message[i]>='A'&&message[i]<='Z')
message[i]=(message[i]+shift-'A')%26+'A';
}
//end
}
ps.比较难也比较复杂! 复制了一下老师的版本,用到“计数器”
#include
int main()
{
char a[100], ch;
int i = 0, word = 0, f = 1;
printf("Enter a sentence: ");
i = 0;
while (1)//逐个输入
{
a[i] = getchar();//把输入的第一个字符放到a[i]里
if (a[i] == '?' || a[i] == '!' || a[i] == '.')//句末符号,退出判断并记录
{
ch = a[i];
break;
}
if (a[i] != ' ' && f == 1)//统计单词数(f=1为“计数器可用”,在开始写入单词后立马f=0,表示目前在写的单词已经计数了,计数器不可用)
{
word++;
f = 0;
}
if (a[i] == ' ' && f == 0)//一个单词输入完成(让f=1,表示计数器可用,可以开始下一个单词输入)
f = 1;
i++;
}
ch = a[i];
a[i] = '\0';
printf("Reversal of sentence: ");
/*以下为输出部分*/
f = 0;//因为最后一个字符非字母,所以f=0不能输出
while (i != -1)
{
if (a[i] == ' ' || a[i] == '\0')
{
a[i] = '\0';//这里从后往前把单词单独切开
if (f == 1)//f=1才能输出
{
f = 0;
if (word > 1)
printf("%s ", a + i + 1);
else
printf("%s", a + i + 1);
word--;
}
}
else//只要碰到字母,就f=1,表示可以输出
{
if (f == 0)
f = 1;
}
if (i == 0 && a[i] != '\0')
printf("%s", a);
i--;
}
printf("%c\n", ch);
//system("pause");
return 0;
}
int main()
{
int x[10],n,i,k;
while(scanf("%d",&n)!=-1)
{ k=0;
while(n>0)
{
x[k]=n%10;
k++;
n=n/10;
}
for(i=0;i<=(k-1)/2;i++)
if(x[i]!=x[k-1-i])
break;
if(i>(k-1)/2)
printf("1\n");
else
printf("0\n");
}
return 0;
}
int main()
{
int x,y,flag;
while(scanf("%d%d",&x,&y)!=-1)
{
flag=func(x,y);
printf("%d\n",flag);
}
return 0;
}
int func(int x,int y)
{
if(x>y&&x%y==0)
return 1;
else
return 0;
}
int main()
{
int x,k;
while(scanf("%d",&x)!=-1)
{
k=func(x);
printf("%d",k);
}
return 0;
}
int func(int x)
{
int sum,k;
sum=0;
while(x>0)
{
k=x;
k=k%10;
sum=sum*10+k;
x=x/10;
}
return sum;
}
int main()
{
int x,y,k,i,a[200];
int low,high,mid;
while(scanf("%d %d",&x,&y)!=-1)
{
for(i=0;imid)
{
low=mid+1;
k++;
}
if(a[i]high)
printf("%d\n",0);
else
printf("%d\n",k);
}
return 0;
}
int main()
{
char str[100],ch;
while(scanf("%s %c",str,&ch)!=-1)
{
str_len(str,ch);
printf("%s\n",str);
}
return 0;
}
void str_len(char a[],char ch)
{
int i,j,m;
char t;
i=0;
while(a[i]!='\0')
i++;
a[i]=ch;
for(j=0;ja[m+1])
{ t=a[m];
a[m]=a[m+1];
a[m+1]=t;
}
}
void change(char a[],char x,char y)
{
int i=0;
while(a[i]!='\0')
{
if(a[i]==x)
a[i]=y;
i++;
}
}
int main()
{
char a[100],x,y;
int i;
while(scanf("%s %c %c",a,&x,&y)!=-1)
{
change(a,x,y);
printf("%s\n",a);
}
return 0;
}
int main()
{
char str[100],ch;
int x;
while(scanf("%s %c %d",str,&ch,&x)!=-1)
{
str_del(str,ch,x);
printf("%s\n",str);
}
return 0;
}
void str_del(char str[],char ch,int x)
{
int i,j;
i=0;j=0;
while(str[i]!='\0')
{
if(str[i]!=ch)
{
str[j]=str[i];
j++;
}
i++;
}str[j]='\0';
for(j=0;str[j]!='\0';j++)
{
if(str[j]>='a'&&str[j]<='z')
str[j]=(str[j]-'a'+x)%26+'a';
}
}
void func_xx(int a[],int n)
{
//start
int i,j,temp;
for(i=0;i
int main()
{
int i,m,a[10];
//start //end
while(scanf("%d",&a[0])!=-1)
{
for(i=1;i<10;i++)
scanf("%d",&a[i]);
func_xx(a,10);
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\n");
}
return 0;
}
void func_xx(int b[],int n)
{
//start
int i,temp,max_pos,min_pos;
max_pos=min_pos=0;
for(i=1;ib[max_pos])
max_pos=i;
if(b[i]
#include
#include
int main()
{
double data[10];
int tmp,i,j,k;
while(scanf("%lf",&data[0])!=-1)
{
for(i=1;i<10;i++)
scanf("%lf",&data[i]);
func_sort(data,10);
for(i=0;i<10;i++)
printf("%.1lf ",data[i]);
printf("\n");
}
return 0;
}
void func_sort(double a[],int n)
{
//start
int i,j;
double t;
for(i=0;i<10-1;i++)
for(j=0;j<10-i-1;j++)
if(a[j]
int main()
{
char str[100],dst[100];
while(scanf("%s",str)!=-1)
{
str_copy(str,dst);
printf("After Copy:%s\n",dst);
}
return 0;
}
void str_copy(char s[],char d[])
{
int i;
i=0;
while(s[i]!='\0')
{
d[i]=s[i];
i++;
}
d[i]='\0';
}
int main()
{
char str[100],dst[100];
int k;
while(scanf("%s %s",str,dst)!=-1)
{
k=str_cmp(str,dst);
printf("%d\n",k);
}
return 0;
}
int str_cmp(char a[],char b[])
{
int m,n,i;
m=0;
while(a[m]!='\0')
m++;
n=0;
while(a[n]!='\0')
n++;
i=0;
if(m<=n)
{
while(a[i]!='\0')
{
if(a[i]==b[i])
i++;
else
if(a[i]>b[i])
return 1;
else
return -1;
}
return 0;
}
if(m>n)
{
while(b[i]!='\0')
{
if(a[i]==b[i])
i++;
else
if(a[i]>b[i])
return 1;
else
return -1;
}
return 0;
}
}
int main()
{
char s[100],t[100],q[100];
while(scanf("%s %s",s,t)!=-1)
{
str_cat(s,t,q);
printf("%s\n",q);
}
return 0;
}
void str_cat(char s[],char t[],char q[])
{
int i,j;
for(i=0;s[i]!='\0';i++)
q[i]=s[i];
for(j=0;t[j]!='\0';j++)
q[i+j]=t[j];
q[i+j]='\0';
}
emm
int main()
{
int least_common_multiple(int x, int y);
int x, y, z;
scanf("%d%d%d",&x,&y,&z);
printf("%d\n",least_common_multiple(least_common_multiple(x,y),z));
return 0;
}
int least_common_multiple(int x, int y)
{
int i,t,k;
if(x0;i++)
{
if(i%x==0&&i%y==0)
break;
}
return i;
}
int main()
{
int x,y,t,i;
scanf("%d %d",&x,&y);
if(x>y)
{
t=y;
y=x;
x=t;
}
for(i=x;i>0;i--)
{
if(x%i==0&&y%i==0)
break;
}
printf("%d\n",i);
return 0;
}
#include
#include
int main()
{
int computer;
int me;
scanf("%d",&me);
//start
computer=rand()%3+1;
if(computer-me==0)
printf("Draw.");
if(computer-me==1||me-computer==2)
printf("You win.");
if(me-computer==1||computer-me==2)
printf("You lose.");
//end
return 0;
}
int main()
{
int x,j,k,m;
char a[100],c[100];
char *b="0123456789ABCDEFGH";
scanf("%d",&x);
j=0;
while(x!=0)
{
k=x%18;
a[j]=b[k];
x=x/18;
j++;
}
a[j]='\0';
m=j-1;
j=0;
while(a[j]!='\0')
{
c[m]=a[j];
m--;
j++;
}
c[j]='\0';
printf("%s",c);
return 0;
}
输入:ababaabcc
输出:3
int len(char b[])
{
int i=0;
while(b[i]!='\0')
i++;
return i;
}
int main()
{
int flag,sum=0,l,i,j,k;
char a[100],b[100];
scanf("%s %s",a,b);
l=len(b);
for(i=0;a[i]!='\0';i++)
{
flag=0;
k=i;
if(a[i]==b[0])
{
for(j=1;j
int main()
{
char str[100];
int alp[26] = {0};
scanf("%s", str);
for (int i = 0; i < strlen(str); i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
alp[str[i] - 'a']++;
}
for (int i = 0; i < 26; i++)
if (alp[i] != 0)
printf("%c %d\n", i + 'a', alp[i]);
return 0;
}