UVA 1225-Digit Counting

来源:互联网 发布:校园网络诈骗类型 编辑:程序博客网 时间:2024/05/04 20:08

UVA 1225-Digit Counting

题目大意。输入一个数 N 求 1~N 中 各有几个0~9 的数字

解题思路:循环取整求余

#include<stdio.h>#include<iostream>using namespace std;int main(){ int i,n,j,m,x,c,s[10]; cin>>n; for(i=0;i<n;i++) { for(j=0;j<10;j++)    s[j]=0; cin>>x; for(j=1;j<=x;j++)  {   for(m=j;m/10!=0;m=m/10)    {     c=m%10;     s[c]++;    }    c=m;    s[c]++;  }  for(j=0;j<9;j++)     cout<<s[j]<<" ";  cout<<s[9]<<endl; }return 0;}
0 0
原创粉丝点击