华为机试—数目字逆序且求个位数乘积
华为机试—数字逆序且求个位数乘积

#include <iostream> #include <string> using namespace std; //逆序 string revs(string s){ int j = s.length()-1; int i=0; char t; while(i<j){ t = s[i]; s[i++]=s[j]; s[j--]=t; } return s; } //个位乘积 int chen(string s){ int ans =1; for(int i=0;i<s.length();i++){ ans = ans*(s[i]-'0'); } return ans; } int main() { string s; cin>>s; string ss = revs(s); int n=chen(s); cout<<ss<<" "<<n<<endl; return 0; }
- 1楼wdkirchhoff昨天 00:49
- lz是不是写的有问题?输入30试试?
- Re: wtyvhreal昨天 10:10
- 回复wdkirchhoffn没问题的。
- Re: wdkirchhoff昨天 22:13
- 回复wtyvhrealn30的结果是03
- Re: wtyvhreal昨天 23:03
- 回复wdkirchhoffn逆序本来就是03啊,乘积是0啊
- Re: wdkirchhoff昨天 23:05
- 回复wtyvhrealn数字哪有03的。。那要是30000,你还输出00003不成?
- Re: wtyvhreal昨天 23:13
- 回复wdkirchhoffnnflag = 0;nfor循环遍历nif(a[i]=='0' && flag==0) continue;nflag=1;nb[j++]=a[i]n输出b
- Re: wdkirchhoff昨天 23:22
- 回复wtyvhrealnlz回答的 啥意思?这块代码和你写的不对应啊,a和b哪来的
- Re: wtyvhreal9小时前
- 回复wdkirchhoffn举个列子么,新开一个串,把前面的0过滤掉