#29961: 請問為什麼第三行的宣告不能寫在 int main 裡面


ychsing0927@gmail.com (拜託教我打)

學校 : 臺北市立百齡高級中學
編號 : 167849
來源 : [118.168.141.169]
最後登入時間 :
2023-06-26 15:07:13
c295. APCS-2016-1029-2最大和 -- 2016年10月APCS | From: [111.248.240.9] | 發表日期 : 2022-04-16 18:36

#include <bits/stdc++.h>

using namespace std;

int n,m,sum,arr[25];

int main(){

 

cin >> n >>m;

for (int i=0;i<n;i++){

int Max=0;

for(int j=0,tmp;j<m;j++){

cin >> tmp;

Max=max(Max,tmp);

}

arr[i]=Max;

sum+=Max;

}

cout << sum <<'\n';

bool found = false;

for(int i=0;i<n;i++){

if(sum%arr[i]==0){

if(found) cout << ' ';

    else found=true;

cout << arr[i]; 

}

    }

    if(!found){

    cout << "-1" <<'\n';

}

return 0;

}

 
#29962: Re:請問為什麼第三行的宣告不能寫在 int main 裡面


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
c295. APCS-2016-1029-2最大和 -- 2016年10月APCS | From: [110.28.100.115] | 發表日期 : 2022-04-16 21:07

#include <bits/stdc++.h>

using namespace std;

int n,m,sum,arr[25];

int main(){

 

cin >> n >>m;

for (int i=0;i<n;i++){

int Max=0;

for(int j=0,tmp;j<m;j++){

cin >> tmp;

Max=max(Max,tmp);

}

arr[i]=Max;

sum+=Max;

}

cout << sum <<'\n';

bool found = false;

for(int i=0;i<n;i++){

if(sum%arr[i]==0){

if(found) cout << ' ';

    else found=true;

cout << arr[i]; 

}

    }

    if(!found){

    cout << "-1" <<'\n';

}

return 0;

}


sum沒有初始化

 
ZeroJudge Forum