1 条题解

  • 0
    @ 2026-5-18 23:36:02

    P9940

    贪心思路

    看看听到字母的顺序,如果第 ii 个字母的出现位置比第 i1i-1 个字母出现位置靠前,那么一定又多唱了一首歌。

    code

    #include<bits/stdc++.h>
    using namespace std;
    string s,t;
    int tmp[30];
    int ans=1,q;
    int main(){
    	cin>>t>>s;
    	for(int i=0;i<26;i++)tmp[t[i]-'a']=i;
    	for(int i=0;i<s.length();i++){
    		if(i==0)continue;
    		if(tmp[s[i]-'a']<=tmp[s[i-1]-'a'])ans++;//康康是否多唱了一首歌
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    7069
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    21
    已通过
    13
    上传者