#24430: 可參考的c++簡單解法


thomas.song.7@gmail.com (thomas)

學校 : 國立嘉義高級中學
編號 : 116265
來源 : [140.115.136.255]
最後登入時間 :
2024-04-24 20:29:34
f374. 分組 Grouping -- TOI 練習賽202010新手組2 | From: [1.175.106.6] | 發表日期 : 2021-02-17 13:36

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int g,n;

    while(cin>>g>>n)

    {

        int temp=0;

        int j=0;

        int maxx=0;

        while(n>0)

        {

            int sum=0;

            for(int i=0;i<g;i++)

            {

                if(n>0)

                {

                    sum=sum+n%10;

                    n=n/10;

                }

                else

                    break;

            }

            j=j+1;

            maxx=max(maxx,sum);

            if(maxx==sum)

                temp=j;

        }

        cout<<temp<<' '<<maxx<<endl;

    }

    return 0;

}

 

 
ZeroJudge Forum