String 中find 函数的使用
这个问题呢,也是在实践中遇到的, 所以这里稍微做个记录吧
1、 find 函数返回类型 size_type;
2、find 函数语法:
查找(find)语法:
size_type find( const basic_string &str, size_type index );
size_type find( const char *str, size_type index );
size_type find( const char *str, size_type index, size_type length );
size_type find( char ch, size_type index );
3、说明 :
find()函数: 返回str在字符串中第一次出现的位置(从index开始查找)。如果没找到则返回string::npos, 返回str在字符串中第一次出现的位置(从index开始查找,长度为length)。
4、栗子:
题目1006:ZOJ问题
代码: 这个代码不是我写的值得借鉴 。。。。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
size_t posz=s.find('z');
size_t posj=s.find('j');
int a=posz,b=posj-posz-1,c=s.size()-posj-1;
if(a*b==c&&b>=1)
cout<<"Accepted"<<endl;
else
cout<<"Wrong Answer"<<endl;
}
return 0;
}