——————————————————————————————————————————————————————————
First, the binary conversion
Output Hex: printf ( "% x", num);
Where x case hexadecimal output decision letter case
When a binary output to write a function that stores 0 and 1 with int arrays, but need special sentenced to zero, resulting in judgment forget WA
void bin(int n) { if(n==0)cout<<'0'; else{ int a[100001]; int cnt=0; while(n/2) { a[cnt++]=n%2; n/=2; } if(n%2)a[cnt++]=1; for(int i=cnt-1;i>=0;i--)cout<<a[i];} }
Second, serpentine array
#include<bits/stdc++.h> using namespace std; int t,n,i,j; int a[11][11]; void snake(int n) { memset(a,0,sizeof(a)); int i=1,j=1,cnt=1; while(cnt<(n*n)) { while(j<n&&!a[i][j+1])a[i][j++]=(cnt++); while(i<n&&!a[i+1][j])a[i++][j]=(cnt++); while(j>1&&!a[i][j-1])a[i][j--]=(cnt++); while(i>1&&!a[i-1][j])a[i--][j]=(cnt++); } a[i][j]=n*n; for(i=1;i<=n;i++) { for(j=1;j<=n;j++)cout<<a[i][j]<<' '; cout<<endl; } } int main() { cin>>t; for(int i=0;i<t;i++) { cin>>n; cout<<"case #"<<i<<":\n"; snake(n); } return 0; }
(While loop inside the while loop may be changed for loop)
Key is a time to judge a vacancy is not the first time did not do it because they are written in judging a [i] [j], should actually be a [i + 1] [j] and the like
Three, n factorial the number of zeros in the tail (n <= 1000)
#include<bits/stdc++.h> using namespace std; int T,n,i; int main() { cin>>T; for(i=0;i<T;i++) { cin>>n; cout<<"case #"<<i<<":\n"<<n/5+n/25+n/125+n/625<<endl; } return 0; }