当前位置:网站首页>Stocking but not completely stocking (daily question 2 in spring)

Stocking but not completely stocking (daily question 2 in spring)

2022-06-25 01:50:00 51CTO

A little-known fact is , Cows have their own words :「 Niu Wen 」.

Niu Wenyou  Stocking but not completely stocking ( Spring daily question 2)_ greedy Letters ​​​a​​​ To ​​z​​​ form , But when the cow says Niu Wen , May be familiar to us ​​abcdefghijklmnopqrstuvwxyz​​ Different , She will arrange the letters in a certain order .

To pass the time , cow Bessie Humming the cow alphabet song repeatedly , and Farmer John Wonder how many times she sang .

Given a string of lowercase letters , by Farmer John hear Bessie Sing the letters , Calculation Bessie At least a few times I sang the complete song of the cow alphabet , bring Farmer John Can hear a given string .

Farmer John Not always pay attention to Bessie What you sing , So he may miss listening Bessie Some of the letters sung .

The given string contains only the letters he remembers he hears .

Input format
The first line of input contains  Stocking but not completely stocking ( Spring daily question 2)_ greedy Lowercase letters , by ​​​a​​​ To ​​z​​ The order of the Niu alphabet .

The next line contains a string of lowercase letters , by Farmer John hear Bessie Sing the letters .

Output format
Output Bessie The minimum number of complete niuwen alphabet songs sung .

Data range
The length of the string is not less than  Stocking but not completely stocking ( Spring daily question 2)_#include_03 And not more than  Stocking but not completely stocking ( Spring daily question 2)_ character string _04.

sample input :

      
      
abcdefghijklmnopqrstuvwxyz
mood
  • 1.
  • 2.

sample output :

      
      
3
  • 1.

Sample explanation
In this example , The Niu alphabet is in line with the daily alphabet .

Bessie At least three times .

There may be Bessie I only sang the song of the cow alphabet three times , and Farmer John I heard the following capitalized letters .

      
      
abcdefghijklMnOpqrstuvwxyz
abcdefghijklmnOpqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
  • 1.
  • 2.
  • 3.

      
      
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

const int N = 1010;

char a[ 30], s[ N];
int pos[ 30];

int main(){

scanf( "%s", a);
for( int i = 0; i < 26; i ++) pos[ a[ i] - 'a'] = i;

scanf( "%s", s);
int n = strlen( s);

int pre = 30;
int res = 0;
for( int i = 0; i < n; i ++){

int x = pos[ s[ i] - 'a'];
if( x <= pre) res ++;
pre = x;
}

cout << res << endl;

return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242133161997.html