加密
代码语言:javascript复制#include <stdio.h>
#include<string.h>
int main()
{
char a[500];
// scanf("%s",a);
gets(a);
for(int i=0;i<strlen(a);i )
{
if((a[i]>='a'&&a[i]<='v')||(a[i]>='A'&&a[i]<='V'))
a[i]=a[i] 4;
else if((a[i]>='w'&&a[i]<='z')||(a[i]>='W'&&a[i]<='Z'))
a[i]=a[i]-22;
}
// printf("%sn",a);
puts(a);
return 0;
}
代码语言:javascript复制#include <stdio.h>
#include <string.h>
int main() {
int a[10] = {6, 1, 9, 2, 0, 3, 4, 7, 5, 8};
int min, index, tmp;
int i, j, n;
n = sizeof(a) / sizeof(a[0]); //数组有多少个数
for (i = 0; i < n - 1; i ) {
min = a[i];
index = i;
for (j = i 1; j < n; j ) {
if (min > a[j]) {
min = a[j];
index = j;
}
}
if (i != index) {
tmp = a[i];
a[i] = a[index];
a[index] = tmp;
}
}
for (i = 0; i < n; i )
printf("%d ", a[i]);
return 0;
}
代码语言:javascript复制#include <stdio.h>
#include<math.h>
int main()
{
int a,b,c,n,rem;
scanf("%d",&n);
int j=0,i=0;
int tmp=n;
for(i;i<=n/10;i ){
for(j=0;j<=n/20;j ){
c=19*i 23*j;
rem=n-c;
if(rem<=tmp&&rem>=0){
a=i;
b=j;
tmp=rem;
}
}
}
printf("19m:%d, 23m:%d, remain:%d",a,b,tmp);
return 0;
}
冒泡排序法
代码语言:javascript复制#include<stdio.h>
#include<string.h>
int main()
{
int a[]={1,8,2,0,4,5,7,3,6,9};
int i,j;
int n,tmp;
n=sizeof(a)/sizeof(a[0]);
for(i=n-1;i>0;i--)
{
for(j=0;j<i;j )
{
if(a[j]>a[j 1])
{
tmp=a[j];
a[j]=a[j 1];
a[j 1]=tmp;
}
}
}
for(i=0;i<n;i )
printf("%d ",a[i]);
return 0;
}
哨兵法排序
代码语言:javascript复制#include<stdio.h>
#include<string.h>
int main()
{
int a[]={1,8,2,0,4,5,7,3,6,9};
int i,j;
int n,tmp;
n=sizeof(a)/sizeof(a[0]);
for(i=1;i<n;i )
{
tmp=a[i];
for(j=i-1;j>=0&&a[j]>tmp;j--)
{
a[j 1]=a[j];
}
a[j 1]=tmp;
}
for(i=0;i<n;i )
{
printf("%d ",a[i]);
}
return 0;
}