Codeforces Round #339 (Div. 2) B. Gena's Code

題目鏈接~~
題意是求隊列的乘積,而n個數的隊列中的數字至少有n-1個最多隻有1個1的沒有前導零的數,所以這個乘積結果只需記錄結尾總共有多少零,以及不是隻有1個1的數即可。由於位數可以達到10^10所以不能用大數。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s;
string num,ans;
int main()
{
   int n;
   ans="1";
   long long mx=0;
   int j;
   cin>>n;
   for(int i=0;i<n;i++){
         s.clear();
      cin>>s;
   //cout<<s<<endl;
      num.clear();
      if(s=="0"){
         ans="0";
      }
      if(ans=="0") continue;
      j=s.size()-1;
         while(j>=0&&s[j]=='0'){
            mx++;
            j--;
         }
         for(int k=0;k<=j;k++)
            num+=s[k];
           // cout<<num<<endl;
      if(num>"1"){
            ans=num;
      }
   }
   cout<<ans;
   if(ans!="0"){
        // cout<<mx<<endl;
      while(mx>0){
         cout<<"0";
         mx--;
      }

   }
 cout<<endl;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章