高精度乘法,支持浮點運算。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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章