当前位置:网站首页>P1308 [noip2011 popularity group] count the number of words
P1308 [noip2011 popularity group] count the number of words
2022-07-07 23:40:00 【Yuesi】
P1308 -NOIP2011 Popularization group - Count the number of words
See blog links
General text editors have the function of finding words , This function can quickly locate the position of specific words in the article , Some can also count the number of times a specific word appears in the article .
Now? , Please program to realize this function , The specific requirement is : Given a word , Please output the number of times it appears in a given article and the location of its first appearance . Be careful : When matching words , Case insensitive , But it requires a perfect match , That is to say, a given word must be exactly the same as an independent word in the article regardless of case ( See example 1 ), If a given word is only a part of a word in the article, it is not a match ( See example 2 ).
Input format
common 2 That's ok .
The first 1 Acts as a string , There are only letters in it , For a given word ;
The first 2 Acts as a string , It can only contain letters and spaces , Represents a given article .
Output format
a line , If a given word is found in the text, output two integers , Two integers are separated by a space , They are the number of times the words appear in the article and the first place they appear ( That is, when it first appears in the article , The position of the first letter of a word in the article , Location slave 00 Start ); If the word doesn't appear in the text , Then output an integer directly -1−1.
I/o sample
Input #1
To
to be or not to be is a question
Output #1
2 0
Input #2
to
Did the Ottoman Empire lose its power at that time
Output #2
-1
explain / Tips
Data range
1≤ Word length ≤10.
1≤ The length of the article ≤1,000,000.
noip2011 Popularization Group No 2 topic
It's easy to get wrong :
This question requires you to find words instead of the same part of other sentences or words
( use find ( ) Direct search may lead to this error )
cin>>a Then consider the next getline ( cin,b) Will you read the previous carriage return
The code is as follows
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
int l,l1;// The corresponding length of the two
cin>>a;
getchar();// Prevent subsequent carriage returns from being read into the string b
getline(cin,b);
l=a.length();
l1=b.length();
int ge=0;
for(int i=0;i<l;i++){
a[i]=tolower(a[i]);
}
for(int i=0;i<l1;i++){
b[i]=tolower(b[i]);
}
a=' '+a+' ';// Find as word
b=' '+b+' ';
if(b.find(a)==-1){
// If you can't find it
printf("-1\n");
}else{
int n=b.find(a);
int m=n;
while(m!=-1){
ge++;
m=b.find(a,m+1);
}
printf("%d %d\n",ge,n);// Output the number of occurrences and the location of the first occurrence
}
return 0;
}
边栏推荐
- Dependency injection 2 advantage lifecycle
- Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- Get started with mongodb
- 数据库面试题+解析
- B_ QuRT_ User_ Guide(36)
- SAP memory parameter tuning process
- B_QuRT_User_Guide(36)
- Possible SQL for Oracle table lookup information
- 数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
猜你喜欢

Lm12 rolling heikin Ashi double K-line filter

神奇快速幂

New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held

2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?

Dataguard 主备清理归档设置

Ora-02437 failed to verify the primary key violation

SAP HR 劳动合同信息 0016

ESP at installation esp8266 and esp32 versions

SAP HR奖罚信息导出

Class C design questions
随机推荐
The file format and extension of XLS do not match
0-1 knapsack problem
UE4_ Ue5 panoramic camera
网上买基金安全么?
May day d-light
One week learning summary of STL Standard Template Library
B_ QuRT_ User_ Guide(36)
Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
【7.4】25. Turn over the linked list in groups of K
Take you hand in hand to build Eureka server with idea
Learn about scratch
Oracle statistics by time
aws-aws help报错
How to change the formula picture in the paper directly into the formula in word
Reverse output three digit and arithmetic sequence
C method question 2
JNI uses asan to check memory leaks
MySQL架构
IDEA 2021.3. X cracking