栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

String Builder (15 分)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/628983.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号