首页 > 其他分享 >892.2019

892.2019

时间:2022-12-01 23:44:07浏览次数:38  
标签:std 892.2019 int namespace cin include cout

1:

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

int main(){
    int n;
    cin >> n;
    if(n >= 90)	cout << 'A';
    else if(n >= 80) cout  << 'B';
    else if(n >= 70) cout << 'C';
    else if(n >= 60) cout << 'D';
    else 	cout << 'E';
     
    return 0;
}

  

2:

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

int main(){
    int n = 8, a[10];
    for(int i = 0; i < n; i++){
    	cin >> a[i];
	}
    for(int i = 7; i >= 0; i--){
    	if(a[i] & 1)	cout << a[i] << " ";
	}
     
    return 0;
}

  

3:

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

bool check(int x){
	string s = to_string(x);
	for(int i = 0; i < s.length(); i++){
		if(s[i] == '3') return 1;
	}
	return 0;
}
int main(){
    int a, b;
    cin >> a >> b;
    for(int i = a; i <= b; i++){
    	if(check(i)) cout << i << " ";
	}
     
    return 0;
}

  

4:

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

int main(){
	//使用桶排序 
    int x, grade[105], k = 1, cnt = 0;
    cin >> x;
    memset(grade, 0, sizeof(grade));//初始化:将数组grade全部初始化为0 
    while(x != -1){
    	grade[x] = k++;
    	cin >> x;
	}
    for(int i = 100; i >= 0; i--){
    	if(grade[i] != 0){
    		cout << grade[i] << "号" << i << "分 ";
			cnt++;
			if(cnt >= 10)break; 
		}
	} 
    return 0;
}

  

5:

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

int Sum(int n){
	if(n){
		int x;
		cin >> x;
		return x + Sum(n - 1);
	}
	return 0;
}
int main(){
	int n;
	cin >> n;
	cout << Sum(n) ;
    return 0;
}

  

6:

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

bool is_prime(int x){
	if(x < 2)return 0;
	if(x == 2)return 1;
	for(int i = 2; i <= sqrt(x); i++){
		if(x % i == 0)return 0;
	}
	return 1;
}
int main(){
	int n, cnt = 0, ans = 0;
	cin >> n;
	for(int i = n + 1; cnt < 5; i++){
		if(is_prime(i)){
			cnt++;
			ans += i;
		}
	}
	cout << ans;
    return 0;
}

  

7:

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

int main(){
	string s;
	int sum = 0, t = 0;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] >= '0' && s[i] <= '9'){
			t = t * 10 + (s[i] - '0');
		}else{
			sum += t;
			t = 0;
		}
	}
	if(t) sum += t;
	cout << sum << endl;
    return 0;
}

  

8:

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

int main(){
	int flag = 0, x, y, ans;
	while(1){
		cout << "请输入指令,1-加,2-减,3-乘,4-除,5-退出" << endl;
		cin >> flag;
		if(flag == 5)break;
		cin >> x >> y;
		if(flag == 1)	ans = x + y;
		else if(flag == 2)	ans = x - y;
		else if(flag == 3)	ans = x * y;
		else if(flag == 4)	ans = x / y;
		cout << "运算结果为:" << ans << endl;
	}
    return 0;
}

  

 

标签:std,892.2019,int,namespace,cin,include,cout
From: https://www.cnblogs.com/rongrongrong/p/16943164.html

相关文章