- 论坛徽章:
- 0
|
<DIV>
<DIV class=codeText id=codeText>
<OL class=dp-css style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-TOP: 5px">
<LI><SPAN style="COLOR: #000000"><SPAN style="COLOR: #0000cc">/</SPAN><SPAN style="COLOR: #0000cc">/</SPAN> 16to10<SPAN style="COLOR: #0000cc">.</SPAN>cpp <SPAN style="COLOR: #0000cc">:</SPAN> Defines the entry point <SPAN style="COLOR: #0000ff">for</SPAN> the console application<SPAN style="COLOR: #0000cc">.</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000cc">/</SPAN><SPAN style="COLOR: #0000cc">/</SPAN><BR></LI>
<LI><BR></LI>
<LI>#include <SPAN style="COLOR: #ff00ff">"stdafx.h"</SPAN><BR></LI>
<LI>#include <SPAN style="COLOR: #0000cc"><</SPAN>iostream<SPAN style="COLOR: #0000cc">></SPAN><BR></LI>
<LI>#include <SPAN style="COLOR: #0000cc"><</SPAN><SPAN style="COLOR: #ff0000">string</SPAN><SPAN style="COLOR: #0000cc">></SPAN><BR></LI>
<LI>#include <SPAN style="COLOR: #0000cc"><</SPAN>ctype<SPAN style="COLOR: #0000cc">.</SPAN>h<SPAN style="COLOR: #0000cc">></SPAN><BR></LI>
<LI><BR></LI>
<LI>using namespace std<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><BR></LI>
<LI><SPAN style="COLOR: #ff0000">int</SPAN> _16to10<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">string</SPAN> content<SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #ff0000">int</SPAN> sum<SPAN style="COLOR: #0000cc">=</SPAN>0<SPAN style="COLOR: #0000cc">,</SPAN>fact<SPAN style="COLOR: #0000cc">=</SPAN>1<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">int</SPAN> i<SPAN style="COLOR: #0000cc">=</SPAN>content<SPAN style="COLOR: #0000cc">.</SPAN>size<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">-</SPAN>1<SPAN style="COLOR: #0000cc">;</SPAN>i<SPAN style="COLOR: #0000cc">></SPAN><SPAN style="COLOR: #0000cc">=</SPAN>0<SPAN style="COLOR: #0000cc">;</SPAN>i<SPAN style="COLOR: #0000cc">-</SPAN><SPAN style="COLOR: #0000cc">-</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI> char c<SPAN style="COLOR: #0000cc">=</SPAN>content<SPAN style="COLOR: #0000cc">[</SPAN>i<SPAN style="COLOR: #0000cc">]</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #0000cc">(</SPAN>isdigit<SPAN style="COLOR: #0000cc">(</SPAN>c<SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI> sum<SPAN style="COLOR: #0000cc">+</SPAN><SPAN style="COLOR: #0000cc">=</SPAN>fact<SPAN style="COLOR: #0000cc">*</SPAN><SPAN style="COLOR: #0000cc">(</SPAN>c<SPAN style="COLOR: #0000cc">-</SPAN><SPAN style="COLOR: #0000cc">'</SPAN>0<SPAN style="COLOR: #0000cc">'</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000ff">else</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #ff0000">int</SPAN> result<SPAN style="COLOR: #0000cc">=</SPAN>tolower<SPAN style="COLOR: #0000cc">(</SPAN>c<SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> sum<SPAN style="COLOR: #0000cc">+</SPAN><SPAN style="COLOR: #0000cc">=</SPAN>fact<SPAN style="COLOR: #0000cc">*</SPAN><SPAN style="COLOR: #0000cc">(</SPAN>result<SPAN style="COLOR: #0000cc">-</SPAN><SPAN style="COLOR: #0000cc">'</SPAN>a<SPAN style="COLOR: #0000cc">'</SPAN><SPAN style="COLOR: #0000cc">+</SPAN>10<SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI> fact<SPAN style="COLOR: #0000cc">*</SPAN><SPAN style="COLOR: #0000cc">=</SPAN>16<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI> return sum<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI><BR></LI>
<LI><SPAN style="COLOR: #ff0000">int</SPAN> main<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">int</SPAN> argc<SPAN style="COLOR: #0000cc">,</SPAN> char<SPAN style="COLOR: #0000cc">*</SPAN> argv<SPAN style="COLOR: #0000cc">[</SPAN><SPAN style="COLOR: #0000cc">]</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI> <SPAN style="COLOR: #ff0000">string</SPAN> content<SPAN style="COLOR: #0000cc">=</SPAN><SPAN style="COLOR: #ff00ff">"B0"</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> <BR></LI>
<LI> <SPAN style="COLOR: #ff0000">int</SPAN> result<SPAN style="COLOR: #0000cc">=</SPAN>_16to10<SPAN style="COLOR: #0000cc">(</SPAN>content<SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> cout<SPAN style="COLOR: #0000cc"><</SPAN><SPAN style="COLOR: #0000cc"><</SPAN>result<SPAN style="COLOR: #0000cc"><</SPAN><SPAN style="COLOR: #0000cc"><</SPAN>endl<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI> return 0<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000cc">}</SPAN></SPAN></LI></OL></DIV></DIV> |
|