String Builder (15 分)

String Builder (15 分),第1张

String Builder (15 分)

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
结尾无空行
#include
using 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<					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5634866.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存