{"id":45614,"date":"2023-12-11T15:06:20","date_gmt":"2023-12-11T07:06:20","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=45614"},"modified":"2023-12-11T15:06:20","modified_gmt":"2023-12-11T07:06:20","slug":"%e5%86%99%e4%b8%80%e4%b8%aa%e6%96%b9%e6%b3%95%ef%bc%8c%e6%8a%8a%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e4%b8%ba%e6%95%b0%e5%ad%97%ef%bc%8c%e6%af%94%e5%a6%82-str1234%ef%bc%8c%e5%8f%98%e6%88%90-int-12","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e5%86%99%e4%b8%80%e4%b8%aa%e6%96%b9%e6%b3%95%ef%bc%8c%e6%8a%8a%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e4%b8%ba%e6%95%b0%e5%ad%97%ef%bc%8c%e6%af%94%e5%a6%82-str1234%ef%bc%8c%e5%8f%98%e6%88%90-int-12\/","title":{"rendered":"\u5199\u4e00\u4e2a\u65b9\u6cd5\uff0c\u628a\u5b57\u7b26\u4e32\u8f6c\u4e3a\u6570\u5b57\uff0c\u6bd4\u5982 str=&#8221;1234&#8243;\uff0c\u53d8\u6210 int 1234\u3002\u5e76\u4e14\u6d4b\u8bd5\u8fd9\u4e2a\u7a0b\u5e8f\u3002"},"content":{"rendered":"<p>&#8220;`&#8221;<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-python&quot;&quot; lang=&quot;&quot;python&quot;&quot;&gt;def StrToInt(a):<br \/>\n    res ,mult,flag = 0,1,1<br \/>\n    if not isinstance(a,str):<br \/>\n        raise TypeError(&quot;&quot;a is not str&quot;&quot;)<br \/>\n    if a[0] ==&#039;-&#039; or a[0] == &#039;+&#039;:<br \/>\n        if a[0] == &#039;-&#039;:<br \/>\n            flag = -1<br \/>\n        a = a[1:]<br \/>\n    for i in range(len(a)-1,-1,-1):<br \/>\n        if &#039;9&#039; =a[i] = &#039;0&#039;:<br \/>\n            res +=(ord(a[i]) -48) * mult<br \/>\n            mult = mult *10<br \/>\n        else :<br \/>\n            return 0<br \/>\n    return res * flag<\/p>\n<p>def test_strToInt2(self):<br \/>\n    with pytest.raises(TypeError):<br \/>\n        StrToInt(34)<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-python&quot;&quot; lang=&quot;&quot;python&quot;&quot;&gt;\u6d4b\u8bd5\u7528\u4f8b\uff1a<br \/>\ndef test_strToInt3(self):<br \/>\n    assert StrToInt(&#039;\u6d4b\u8bd5\u8d5b&#039;) == 0<\/p>\n<p>def test_strToInt4(self):<br \/>\n    assert StrToInt(&#039;+2147689&#039;) == 2147689<\/p>\n<p>def test_strToInt5(self):<br \/>\n    assert StrToInt(&#039;45&#039;) == 45<\/p>\n<p>def test_strToInt6(self):<br \/>\n    assert StrToInt(&#039;1a33&#039;) == 0<\/p>\n<p>def test_strToInt7(self):<br \/>\n    assert StrToInt(&#039;-5&#039;) == -5<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; &lt;pre&gt;&lt;code class=&quot;&quot;l [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-45614","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=45614"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45614\/revisions"}],"predecessor-version":[{"id":45615,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45614\/revisions\/45615"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=45614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=45614"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=45614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}