高精度乘法,支持浮点运算。POJ 1001 Exponentiation 顺便总结一下string的常用函数

第一次使用string的insert() 函数,该函数有好几个重载,所以在传参数时要明确地给予类型转换。

插入(insert)
语法:
iterator insert( iterator i, const char &ch );
basic_string &insert( size_type index, const basic_string &str );
basic_string &insert( size_type index, const char *str );
basic_string &insert( size_type index1, const basic_string &str, size_type index2, size_type num );
basic_string &insert( size_type index, const char *str, size_type num );
basic_string &insert( size_type index, size_type num, char ch );
void insert( iterator i, size_type num, const char &ch );
void insert( iterator i, iterator start, iterator end );


insert()函数的功能非常多:

在迭代器i表示的位置前面插入一个字符ch,
在字符串的位置index插入字符串str,
在字符串的位置index插入字符串str的子串(从index2开始,长num个字符),
在字符串的位置index插入字符串str的num个字符,
在字符串的位置index插入num个字符ch的拷贝,
在迭代器i表示的位置前面插入num个字符ch的拷贝,
在迭代器i表示的位置前面插入一段字符,从start开始,以end结束.

 

 

 

查找(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 );


find()函数:

返回str在字符串中第一次出现的位置(从index开始查找)。如果没找到则返回string::npos,
返回str在字符串中第一次出现的位置(从index开始查找,长度为length)。如果没找到就返回string::npos,
返回字符ch在字符串中第一次出现的位置(从index开始查找)。如果没找到就返回string::npos
例如,

    string str1( "Alpha Beta Gamma Delta" );
    unsigned int loc = str1.find( "Omega", 0 );
    if( loc != string::npos )
      cout << "Found Omega at " << loc << endl;
    else
      cout << "Didn't find Omega" << endl;

 

 

c_str
语法:
const char *c_str();


c_str()函数返回一个指向正规C字符串的指针, 内容与本字符串相同.

 

end
语法:
iterator end();


end()函数返回一个迭代器,指向字符串的末尾(最后一个字符的下一个位置).

begin
语法:
iterator begin();


begin()函数返回一个迭代器,指向字符串的第一个元素

 

substr
语法:
basic_string substr( size_type index, size_type num = npos );


substr()返回本字符串的一个子串,从index开始,长num个字符。如果没有指定,将是默认值 string::npos。这样,substr()函数将简单的返回从index开始的剩余的字符串。

 

 

注:该高精度乘法函数是别人写的,自己改了点。发现poj上这题的数据有点弱,原来有点错误的,但却AC了,不过现在改了之后正确了。

发布了20 篇原创文章 · 获赞 8 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章