#31445: c++超級快速解(初學者必看)


jason0713 ((ง⁼ω⁼)งꉂ(ˊᗜˋ*))

學校 : 不指定學校
編號 : 184210
來源 : [61.230.27.185]
最後登入時間 :
2023-12-26 20:02:53
d046. 文文採西瓜 -- 板橋高中教學題 | From: [61.230.89.70] | 發表日期 : 2022-07-31 16:31

#include <iostream>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);//🚄        
    int n,s,ans=0;cin>>n;
    while(cin>>s)if(s<=10)ans++;
    cout<<ans;
}

 
#31446: Re: c++超級快速解(初學者必看)


krameri120 (科科)

學校 : 國立臺南高級工業職業學校
編號 : 102318
來源 : [36.237.212.239]
最後登入時間 :
2024-04-01 14:20:14
d046. 文文採西瓜 -- 板橋高中教學題 | From: [27.246.66.76] | 發表日期 : 2022-07-31 19:45

#include
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);//🚄        
    int n,s,ans=0;cin>>n;
    while(cin>>s)if(s<=10)ans++;
    cout<}

這樣寫法是指說,你n不看,然後會讀到EOF才停止
跟題目的n個資料的狀況會有出路,
雖然說這樣是對的,但不能保證最後一筆輸入完成後,就直接是end of file
如果是想要直接讀到底的話,那也沒有int n的必要,
int s,ans=0;
while(cin>>s){
    if(s<=10){
         ans++;
    }
}
cout<<ans;

 
#31447: Re: c++超級快速解(初學者必看)


krameri120 (科科)

學校 : 國立臺南高級工業職業學校
編號 : 102318
來源 : [36.237.212.239]
最後登入時間 :
2024-04-01 14:20:14
d046. 文文採西瓜 -- 板橋高中教學題 | From: [27.246.66.76] | 發表日期 : 2022-07-31 19:49

#include
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);//🚄        
    int n,s,ans=0;cin>>n;
    while(cin>>s)if(s<=10)ans++;
    cout<}

這樣寫法是指說,你n不看,然後會讀到EOF才停止
跟題目的n個資料的狀況會有出路,
雖然說這樣是對的,但不能保證最後一筆輸入完成後,就直接是end of file
如果是想要直接讀到底的話,那也沒有int n的必要,
int s,ans=0;
while(cin>>s){
    if(s<=10){
         ans++;
    }
}
cout<

int s,ans=0;
cin>>s;//上面少打了(OAO)
while(cin>>s){
    if(s<=10){
         ans++;
    }
}
cout<<ans;

 
ZeroJudge Forum