a149 乘乘樂

a149 乘乘樂


解題思路 : 將輸入的數字用字串儲存、計算

程式碼

/*
a149 乘乘樂
skyblue
https://zerojudge.tw/ShowProblem?problemid=a149
AC (2ms, 324KB)
*/

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //輸入輸出加速程式
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n,v;
    string str;
    cin >> n;
    
    for(int i=0; i<n; i++){
        cin >> str; //將輸入的數字以字串儲存
        v = 1; //相乘的結果初始值設為1
        for(int i=0; i<str.length(); i++){
            v *=(str[i]-'0'); //將各項相乘 轉換ASCII碼
        }
        cout << v <<"\n";
    }

    return 0;
   
}

/*
範例輸入 #1
3
356
123
9999
範例輸出 #1
90
6
6561*/

留言

這個網誌中的熱門文章

a034.二進位轉換

a024.最大公因數(GCD)

d066.上學去吧!