0123456789101112
is a string build up for n=12.
Then, in all the digits from index a to index b, count the appearence of c.
For the string above, 2 5 is:
2345
Thus the appearence of 3 is 1.
Input Format:
Four positive numbers, n, a, b and c, where a
Output Format:
One number represnets the length of the generated string. One number represents the apprence of c. There is a space between the two numbers.
Sample Input: 12 2 5 3 结尾无空行
Sample Output: 16 1 结尾无空行
#includeusing namespace std; int main(){ int n,a,b,c;//12 2 5 3 --->16 1 cin>>n>>a>>b>>c; int j=0,l=0,sum=0; for(int i=0;i<=n;i++){ if(!i){ if(a==0&&c==0) sum++; l++; continue; } j=i; vector v; while(j){ v.push_back(j%10); j/=10; } for(int j=v.size()-1;j>=0;j--){ if(l>=a&&l<=b&&v[j]==c) sum++; l++; } } cout< 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)