#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if (n >= 90) cout << "A";
else if (n <= 89 && n >= 80) cout << "B";
else if (n <= 79 && n >= 70) cout << "C";
else if (n <= 69 && n >= 60) cout << "D";
else cout << "E";
}
#include <iostream>
using namespace std;
int main() {
int odd[8] = {0};
int tmp;
for (int i = 0; i < 8; ++i) {
cin >> tmp;
if (tmp % 2 == 1) {
odd[i] = tmp;
}
}
for (int j = 7; j >= 0; --j) {
if (odd[j] != 0) {
cout << odd[j] << " ";
}
}
}
#include <iostream>
using namespace std;
bool containThree(int num) {
//while (num % 10 != 0) {
//谢谢小伙伴提醒上面这种判断条件是错的,因为会排除30这种情况
while (num > 0) {//改成这样就对了
int tmp = num % 10;
if (tmp == 3) return true;
else num /= 10;
}
return false;
}
int main() {
int a, b;
cin >> a >> b;
for (int i = a; i <= b; ++i) {
if (containThree(i)) {
cout << i << " ";
}
}
}
#include <iostream>
void bubbleSort(int arr[], int arrLength);
int findIndex(int num, int arr[], int arrLen);
using namespace std;
int main() {
int student[100] = {0};
int ordered[100] = {0};
int tmp , flag1 = 0, flag2 = 0;
cin >> tmp;
while (tmp != -1) {
student[flag1++] = tmp;
ordered[flag2++] = tmp;
cin >> tmp;
}
bubbleSort(ordered, flag2);
int index = flag1 < 10 ? flag1 : 10;
for (int i = 0; i < index; ++i) {
cout <<findIndex(ordered[i], student, flag1) << "号" << ordered[i] << "分" << " ";
}
return 0;
}
void bubbleSort(int arr[], int arrLength) {
for (int i = arrLength - 1; i > 0; --i) {
for (int j = 0; j < i; ++j) {
if (arr[j] < arr[j + 1]) {
int tmp;
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
}
int findIndex(int num, int arr[], int arrLen) {
for (int i = 0; i < arrLen; ++i) {
if (arr[i] == num) {
return i+1;
}
}
}
#include <iostream>
using namespace std;
int returnSum(int arr[], int arrLen){
if (arrLen == 0) {
return arr[0];
}
return arr[arrLen] + returnSum(arr, arrLen - 1);
}
int main() {
int n; cin >> n;
int arr[100] = {0};
for (int i = 0; i < n; ++i) {
int tmp; cin >> tmp;
arr[i] = tmp;
}
int res = returnSum(arr, n - 1);//谢谢小伙伴提醒,这里应该传入n-1,否则会造成数组越界。
cout << res;
}
#include <iostream>
#include <math.h>
int getFivePrimeNum(int n);
using namespace std;
int main() {
int n;cin >> n;
cout << getFivePrimeNum(n);
}
int getFivePrimeNum(int n){
int sum = 0;
int flag = 0;
bool isPrimeNum;
for (int i = n + 1; flag < 5; ++i) {
isPrimeNum = true;
for (int j = 2; j <= sqrt(i); ++j) {
if (i % j == 0) {
isPrimeNum = false;
break;
}
}
if (isPrimeNum) {
flag++;
sum += i;
}
}
return sum;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;cin >> s;
int isAFullNum = 0;//前一个字符是不是数字
int sum = 0 ;
int tmp;
for (int i = 0; i < s.size(); ++i) {
if (isAFullNum == 1 && '9' - s[i] >= 0 && '9' - s[i] <= 9) {//前一个是数字,后一个也是数字
tmp *= 10;
tmp = tmp + s[i] - '0';
continue;
}
if (isAFullNum == 0 && '9' - s[i] >= 0 && '9' - s[i] <= 9) {//前一个不是数字,后一个是数字
isAFullNum = 1;
tmp = s[i] - '0';
continue;
}
if (isAFullNum == 1 && !('9' - s[i] >= 0 && '9' - s[i] <= 9) ) {//前一个字符是数字后一个不是数字
sum += tmp;
tmp = 0;
isAFullNum = 0;
}
}
if (tmp!=0) {
sum += tmp;
}
cout << sum;
}
#include <iostream>
using namespace std;
int main() {
int flag;
cout << "请输入指令 1-加,2-减,3-乘,4-除\n" ;
cin >> flag;
while (flag!=5) {
int a, b;
cin >> a >> b;
if (flag == 1){
cout << "运算结果为" << a + b << "\n";
}else if (flag == 2)
cout << "运算结果为" << a - b << "\n";
else if (flag == 3)
cout << "运算结果为" << a * b << "\n";
else if (flag == 4)
cout << "运算结果为" << a / b << "\n";
cout << "请输入指令 1-加,2-减,3-乘,4-除\n" ;
cin >> flag;
}
}
#include <iostream>
using namespace std;
const int QueueSize = 100;//队列最大长度
class CirQueue {//循环队列
int data[QueueSize];//循环队列数组
int front = 0, rear = 0;//队头、队尾指针
int flag = 0;//标志
void EnQueue(int x) {
//判断是否为满
if (front == rear && flag == 1) {
cout << "queue is full";
}else{
data[rear] = x;
rear = (rear + 1) % QueueSize;
}
flag = 1;
}//入队
int DeQueue() {
//判断是否为空
int res;
if (front == rear && flag == 0) {
cout << "queue is empty";
}else {
int x = front + 1;
res = data[x];
data[x] = 0;
front = (front + 1) % QueueSize;
}
flag = 0;
return res;
}//出队
};
第九题可以讨论一下,我感觉我这道题不太确定。