我们可以将0——9看成一个一维数组:a[11]
#include<cstdio>
int a[11],n;
int x,p;
int main(){scanf("%d",&n);for(int i=1;i<=n;i++){p=i;while(p!=0){x=p%10;a[x]++;//让下标x每次出现时增加1(描述不清楚)p/=10;}}for(int i=0;i<=9;i++){printf("%d ",a[i]);}
}
#include<cstdio>
int n,a[21];
int main(){scanf("%d",&n);for(int i=1;i<=n;i++){//行for(int j=1;j<=i-1;j++){printf("%5d",j);}for(int j=1;j<=n-i+1;j++){printf("%5d",i);}printf("\n");}
}
看图:
#include<cstdio>
int n,x,y,a[20010],b[20010],g[20010],k[20010];
int main(){scanf("%d",&n);for(int i=n;i>=1;i--){if(x>=a[i]&&x<=a[i]+g[i]&&y>=b[i]&&y<=b[i]+k[i]){printf("%d ",i);return 0;}}printf("-1");
}