已获得源代码,帮忙写下注释,谢谢
数列:
#include<cstdio>
#include<cstdlib>
#include<iostream>
int a[1000];
using namespace std;
int main(){
int k,n,i=0;
freopen("sequence.in","r",stdin);
freopen("sequence.out","w",stdout);
cin>>k>>n;
do{
a[++i]=n%2;
n/=2;
}
while(n!=0);
int x=1;
int ans=a[1];
for(int j=2;j<=i;j++){
x*=k;
ans+=a[j]*x;
}
cout<<ans<<endl;
return 0;
}
车牌:
#include<bits/stdc++.h>
using namespace std;
int a[500000];
int main(){
freopen("license.in","r",stdin);
freopen("license.out","w",stdout);
string str;
int n=0;
while(getline(cin,str)){//while(scanf("%s",str.c_str()!=EOF) {
int t=0;
for(int j=2;j<7;j++){
if(str[j]>57) t=t*36+str[j]-55;
else t=t*36+str[j]-48;
}
a[n++]=t;
}
n--;
sort(a,a+n);
int ans=a[1]-a[0];
for(int i=2;i<n;i++)
if(a[i]-a[i-1]<ans) ans=a[i]-a[i-1];
cout<<ans<<endl;
return 0;
}