7-3 Counting Lower-case Letters (25 分)

7-3 Counting Lower-case Letters (25 分)
Given a string consisting of lower-case letters chosen from a-z, you can obtain numbers of occurrence of each letter.

Now you are given a string and several intervals of it. And for each interval, you are also given a lower-case letter. Your task is to count the number of corresponding letter in each interval.

Input Specification:
Each input file contains one test case. In each test case, the first line contains a string consisting of no more than 50,000 characters. And the second line contains an integer K (<=10
​5
​​ , the number of queries). Then the following K lines each give information in the format

B E c

where B and E denote the beginning and the end of interval, respectively, and c is a character (a-z). Hence the characters in the given string are indexed from 0 to N−1, where N is the length of the string.

Output Specification:
For each query, print in a line the count of corresponding letter.

Sample Input:
aaabcadeefagg
3
0 3 a
2 5 b
4 7 d
Sample Output:
3
1
1

#include<bits/stdc++.h>
using namespace std;
int main(){
	 //freopen("1.txt","r",stdin);
	 vector<char>s;
	 vector<int> in;
	 char a;
	 int i,n,j=0;
	 int count=0;
	 int st,ed;
	 char b;
	 while((a=getchar())!='\n'){
	 	s.push_back(a);
	 }
	 cin>>n;
	 for(i=0;i<n;i++){
	 	cin>>st>>ed>>b;
	 	for(j=st;j<=ed;j++){
	 		if(s[j]==b){
	 			count++;
	 		}
	 	}
	 	in.push_back(count);
	 	count=0;
	 }
	 for(int m;m<n;m++){
	 	cout<<in[m]<<endl;
	 }
	 return 0;
}

很简单的一道题,但是莫名时间超时…有想法的朋友可以一起来讨论下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值