iT邦幫忙

0

備考CPE-Day3 (必考一顆星49題:5,6)

  • 分享至 

  • xImage
  •  

題目5:
https://ithelp.ithome.com.tw/upload/images/20240904/20163102WJ2c3DKNtl.png


程式碼5:

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

int main(){
    int b;
    string result = "";
    while(cin>>b){
        if(b!=0){
            if(b%11==0){
                result+=to_string(b)+" is a multiple of 11.\n";
            }
            else{
                result+=to_string(b)+" is not a multiple of 11.\n";
            }
        }
        else{
            cout<<result;
            return 0;
        }
    }
    return 0;
}

題目6:
https://ithelp.ithome.com.tw/upload/images/20240905/20163102xtdiW3vXrK.png


程式碼6:

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

void Bangla(long long int n){
    while(n>0){
        if(n>=10000000){
            cout<<" "<<n/10000000<<" kuti";
            n%=10000000;
            continue;
        }
        if(100000<=n&&n<10000000){
            cout<<" "<<n/100000<<" lakh";
            n%=100000;
            continue;
        }
        if(1000<=n&&n<100000){
            cout<<" "<<n/1000<<" hajar";
            n%=1000;
            continue;
        }
        if(100<=n&&n<1000){
            cout<<" "<<n/100<<" shata";
            n%=100;
            continue;
        }
        else{
            cout<<" "<<n;
            break;
        }
    }
}

int main(){
    long long int n;
    int t=1;
    while(cin>>n){
        cout<<setw(4)<<setfill(' ')<<t<<".";
        if(n==0) cout<<" "<<0;
        if(n>=10000000){
            Bangla(n/10000000);
            cout<<" kuti";
            Bangla(n%10000000);
        }
        else{
            Bangla(n);
        }
        cout<<"\n";
        t++;
    }
    return 0;
}


以上程式碼參考:
https://weilin1205.github.io/2022/07/28/UVa/CPEbasic/


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言