C++不同等级输入方式

Teacher_wang Just Do It 2025-02-12 12:23:54 19

示例题目:n个数求和

青铜-cin

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=10000,t,ans=0;
	while(n--){
		cin>>t;
		ans+=t;
	}
	cout<<ans;
	return 0;
}

白银-scanf

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=100000,t,ans=0;
	while(n--){
		scanf("%d",&t);
		ans+=t;
	}
	cout<<ans;
	return 0;
}

黄金-ios

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n=500000,t,ans=0;
	while(n--){
		cin>>t;
		ans+=t;
	}
	cout<<ans;
	return 0;
}

钻石-快读

#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int main(){
    int n=5000000,t,ans=0;
    cin>>n;
    while(n--){
        t=read();
        ans+=t;
    }
    cout<<ans;
    return 0;
}
{{ vote && vote.total.up }}

共 2 条回复

qym 山顶洞人

ios是什么东西

qym 山顶洞人

一般用cin,scanf,快读