数组赋值
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int a[]={1,2,3,4,5,}; 6 int b[6]={0}; 7 memcpy(b,a,sizeof(int)*2); 8 for(int i=0; i<(sizeof(b)/sizeof(b[0])); ++i) // 一开始没写/sizeof(b[0]),怕是傻子 9 printf("%d\n",b[i]); 10 return 0; 11 }
开灯问题
1 #include<stdio.h> 2 #include<string.h> 3 4 const int max = 1010; 5 int a[max]; 6 int main() 7 { 8 int n,k,flag=1; 9 scanf("%d%d",&n,&k); 10 memset(a,0,sizeof(a)); 11 for(int i=1; i<=k; ++i) 12 for(int j=i; j<=n; j+=i) 13 a[j] = !a[j]; 14 for(int i=1; i<=n; ++i){ 15 if(a[i]){ 16 if(flag){ 17 printf("%d",i); 18 flag = 0; 19 } 20 else 21 printf(" %d",i); 22 } 23 } 24 return 0; 25 }