2 条题解

  • 0
    @ 2025-11-12 21:43:33

    这道题目作为这次考试的第一题,难度不大,数据量也很小,简单的重复一下即可。 附上代码:

    #include<bits/stdc++.h>
    using namespace std;
    char az[27],f[1001];
    int x=1,x1=1,a=1,djb=1;
    int main(){
    	for(int i=1;i<=26;i++){
    		cin>>az[i];
    	}
    	while(cin>>f[x]){
    		x++;
    	}
    	x--;
    	while(x1!=x+1){
    		if(a>26){
    			a=1;
    			djb++;
    		}
    		if(az[a]==f[x1]){
    			x1++;
    		}
    		a++;
    	}
    	cout<<djb;
    	return 0;
    }
    
    
    • -1
      @ 2025-11-9 15:22:34

      方法思路 1.记录字母位置:首先,根据给定的牛文字母表,记录每个字母在字母表中的位置(索引)。 2.遍历字符串:遍历Farmer John听到的字符串,检查每个字符在牛文字母表中的位置。 3.判断是否需要新的一遍:对于字符串中的每个字符,如果它在牛文字母表中的位置不严格大于前一个字符的位置,则说明需要新的一遍字母歌。 4.计数:统计需要新的一遍字母歌的次数,初始遍数为1(至少一遍),每次需要新的一遍时递增计数。 代码:

      #include<bits/stdc++.h>

      using namespace std;

      int main(){

      string a,b;
      
      cin>>a>>b;
      
      int c[26];
      
      for(int i=0;i<26;i++)
      
      {
      
          c[a[i] - 'a']=i;
          
      }
      
      if (b.empty())
      
      {
      
          cout<<0<<endl;
          
          return 0;
          
      }
      
      int ans=1;
      
      int l=c[b[0]-'a'];
      
      for (int i=1;i<b.size();i++)
      
      {
      
          int d=c[b[i]-'a'];
          
          if(d<=l)
          
      	{
      
              ans++;
              
          }
          
          l=d;
          
      }
      
      cout<<ans<<endl;
      
      return 0;
      

      }

      • 1

      信息

      ID
      2820
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      递交数
      154
      已通过
      37
      上传者