zoukankan      html  css  js  c++  java
  • 字符串

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<cstdlib>
    using namespace std;
    int main()
    {
    	int repeat,sum,i,j,num,s=0;
    	string st;
    	char ch;
    	cin>>repeat;
    	for(i=0;i<repeat;i++)
    	{
    		cin>>ch>>st;
    		sum=strlen(st.c_str());//写成sum=strlen(st)过不了(错误原因在于st是一个std::string类型的变量,而strlen要求的参数是char*类型的
      //如果要获取st字符串的长度,std::string自带一个size接口可以满足需求
      //如果仍要继续使用strlen,则可以使用std::string的c_str接口。该接口返回一个const char*指针,正好可以作为参数传递给strlen)
    		for(j=sum;j>=0;j--)
    		{
    			if(ch==st[j])
    			{
    				num=j;
    				cout<<"index "<<"= "<<num<<endl;
    				s=1;
    				break;
    			}
    		}
    		if(s!=1)
    		{
    			cout<<"Not Found"<<endl;
    		}
    		s=0;
    	}
    	return 0;
     }
    
  • 相关阅读:
    最小生成树
    图论最短路径例题
    广搜例题
    这些搜索套路好深。。。
    高斯消元part2
    高斯消元与行列式求值 part1
    2020/4/24
    实时的眼部追踪
    2020/4/23
    2020/4/22
  • 原文地址:https://www.cnblogs.com/qq805212031/p/5550913.html
Copyright © 2011-2022 走看看