[Lab104] G

xiaoxiao2021-02-27  999

#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n,m,i; long long count,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9;//超int范围 char N[100000];//**数组开大一点** char c[6]; cin>>n; while(n--) { cin>>m; count=0; a0=a1=a2=a3=a4=a5=a6=a7=a8=a9=0; for(i=1;i<m+1;i++) { if(i==1) { sprintf(c,"%d",i);//**整型改字符型** strcpy(N,c); count=count+1; } else { sprintf(c,"%d",i); strcat(N,c); if(0<i&&i<=9) { count=count+1; } else if(i>9&&i<100) { count=count+2; } else if(i>99&&i<1000) { count=count+3; } else if(i>999&&i<10000) { count=count+4; } } } for(i=0;i<count;i++) { if(N[i]=='0') { a0++; } else if(N[i]=='1') { a1++; } else if(N[i]=='2') { a2++; } else if(N[i]=='3') { a3++; } else if(N[i]=='4') { a4++; } else if(N[i]=='5') { a5++; } else if(N[i]=='6') { a6++; } else if(N[i]=='7') { a7++; } else if(N[i]=='8') { a8++; } else if(N[i]=='9') { a9++; } } cout<<a0<<" "<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<" "<<a5<<" "<<a6<<" "<<a7<<" "<<a8<<" "<<a9<<endl; memset(N,0,10000); memset(c,0,6); } return 0; } //代码繁琐待改进
转载请注明原文地址: https://www.6miu.com/read-331.html

最新回复(0)