完成了暨大计算机复试的所有真题

This commit is contained in:
carry 2025-03-22 20:00:04 +08:00
parent 755923c349
commit cb17a48cc9
26 changed files with 743 additions and 0 deletions

32
2014冒泡排序.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
int n,temp;
cin >> n;
vector<int> array;
for (int i = 0; i < n; i++) {
cin >> temp;
array.push_back(temp);
}
for (int i = 0; i < n; i++) {
for(int j = 0;j < n - 1;j++){
if(array[j] > array[j + 1]){
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
for(auto i: array){
cout << i << " ";
}
return 0;
}

28
2014矩形覆盖.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
int m,n,a;
cin >> m >> n >> a;
if(m%a == 0){
m = m/a;
}
else{
m = m/a + 1;
}
if(n%a == 0){
n = n/a;
}
else{
n = n/a + 1;
}
cout << m*n;
return 0;
}

31
2014砍树修路.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<iostream>
#include<vector>
using namespace std;
int main(){
int L;
cin >> L;
int n;
cin >> n;
int a,b;
vector<int> route(L + 1,1);
for(int i = 0;i < n;i++){
cin >> a >> b;
for(int j = a;j <= b;j++){
route[j] = 0;
}
}
int counter = 0;
for(auto i:route){
counter += i;
}
cout << counter;
return 0;
}

28
2015元音处理.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
string str;
cin >> str;
for(auto i:str){
switch(i){
case 'a':case 'o':case 'e':case 'i':case 'u':
case 'A':case 'O':case 'E':case 'I':case 'U':
break;
default:
cout << '.';
if(i < 92){
printf("%c",i+32);
}
else{
printf("%c",i-32);
}
}
}
return 0;
}

22
2015高精度乘法.cpp Normal file
View File

@ -0,0 +1,22 @@
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
string str;
vector<int> num1,num2;
cin >> str;
for(auto i:str){
num1.push_back(stoi(&i));
}
cin >> str;
for(auto i:str){
num2.push_back(stoi(&i));
}
return 0;
}

28
2016字符统计.cpp Normal file
View File

@ -0,0 +1,28 @@
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
int counter_at = 0;
int counter_endl = 1;
while(1){
cin >> str;
for(auto i = str.begin()+1;i != str.end();i++){
if((*(i-1) == 'a')&&(*i == 'a')){
counter_at++;
}
}
if(*(str.end()-1) == '.'){
break;
}
else{
counter_endl++;
}
}
cout << counter_at << endl << counter_endl << endl;
return 0;
}

31
2016猜数字.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<iostream>
#include<string>
using namespace std;
int main(){
int max,target;
cin >> max >> target;
int min = 1;
int guest = -1;
int counter = 0;
while(1){
counter++;
guest = (max - min + 1)/2 + min;
//cout << counter << " " << guest << " "<< max << "~" << min << endl;
if(guest > target){
max = guest;
}
else if(guest < target){
min = guest;
}
else{
break;
}
}
cout << counter;
return 0;
}

32
2017成绩排名.cpp Normal file
View File

@ -0,0 +1,32 @@
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
int n,temp;
vector<int> array;
set<int,greater<int>> score;
cin >> n;
for(int i = 0;i < n;i++){
cin >> temp;
score.insert(temp);
}
cin >> n;
temp = 1;
for(auto i = score.begin();i != score.end();i++){
if(*i != n){
temp++;
}
else{
cout << temp;
break;
}
}
return 0;
}

31
2017数塔路径.cpp Normal file
View File

@ -0,0 +1,31 @@
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
vector<vector<int>> tree(n);
int temp;
for(int i = 0;i<n;i++){
for(int j = 0;j < i+1;j++){
cin >> temp;
tree[i].push_back(temp);
}
}
vector<vector<int>> dp = tree;
for(int i = n - 2;i >= 0;i--){
for(int j = i;j >= 0;j--){
dp[i][j] = max(dp[i + 1][j],dp[i + 1][j + 1]) + tree[i][j];
}
}
cout << dp[0][0];
return 0;
}

42
2017计算第几天.cpp Normal file
View File

@ -0,0 +1,42 @@
#include<iostream>
using namespace std;
int is_runnian(int y){
return (y%4 == 0)&&(y%2000 != 0);
}
int main(){
int counter;
int y,m,d;
cin >> y >> m >> d;
if(m <= 2){
cout << (m - 1)*31 + d;
return 0;
}
else if(m <= 7){
counter = 31 + 28 + is_runnian(y) + d;
for(int i = 3;i<m;i++){
if(i %2 == 0){
counter += 30;
}
else{
counter += 31;
}
}
}
else{
counter = 212 + is_runnian(y) + d;
for(int i = 8;i<m;i++){
if(i %2 == 0){
counter += 31;
}
else{
counter += 30;
}
}
}
cout << counter;
return 0;
}

25
2018偶数分解.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<iostream>
using namespace std;
int is_sushu(int n){
for(int i = 2;i*i<n;i++){
if(n%i == 0){
return 0;
}
}
return 1;
}
int main(){
int n;
cin >> n;
for(int i = 2;i<=n/2;i++){
if(is_sushu(i)&&is_sushu(n-i)){
cout << i << " " << n - i << endl;
}
}
return 0;
}

View File

@ -0,0 +1,22 @@
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int a=0,b=1;
if((n == 1)||(n == 0)){
cout << n;
return 0;
}
for(int i = 1;i<n;i++){
a = a + b;
swap(a,b);
}
cout << b;
return 0;
}

View File

@ -0,0 +1,41 @@
#include<iostream>
#include<vector>
using namespace std;
int sum(vector<int> array,int start,int end){
int num = 0;
for(int i = start;i <=end ;i++){
num += array[i];
}
return num;
}
int main(){
int n;
cin >> n;
vector<int> array(n);
for(auto &i:array){
cin >> i;
}
int max = 0;
int start = 0;
int end = 0;
for(int i = 0;i < n;i++){
for (int j = 0;j < n - i;j++){
if(max<sum(array,j,j+i)){
max = sum(array,j,j+i);
start = j;
end = j+i;
}
}
}
cout << max << " " << start+1 << " " << end+1 << endl;
return 0;
}

23
2018蛇形矩阵.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for(int i = 1;i<=n;i++){
if(i%2 != 0){
for(int j=(i-1)*n+1;j<=i*n;j++){
cout << j << " ";
}
}
else{
for(int j=i*n;(i-1)*n+1<=j;j--){
cout << j << " ";
}
}
cout << endl;
}
return 0;
}

26
2019判断回文串.cpp Normal file
View File

@ -0,0 +1,26 @@
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
cin >> str;
auto i = str.begin();
auto j = str.end() - 1;
while(i<j){
if(*i != *j){
cout << "No!" << endl;
return 0;
}
else{
i++;
j--;
}
}
cout << "Yes!" << endl;
return 0;
}

23
2019格子涂色.cpp Normal file
View File

@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
int func(int n){
if(n == 1){
return 0;
}
else if(n == 2){
return 6;
}
else{
return func(n - 1) + func(n - 2)*2;
}
}
int main(){
int n;
cin >> n;
cout << func(n);
return 114514;
}

View File

@ -0,0 +1,38 @@
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> array(n);
for(auto &i:array){
cin >> i;
}
int max_sum = -1;
vector<int> dp(n);
dp[0] = array[0];
for(int i = 1;i < array.size();i++){
dp[i] = array[i];
for(int j = 0;j < i;j++){
if(array[j] < array[i]){
max_sum = max(dp[j],max_sum);
}
}
dp[i] += max_sum;
max_sum = -1;
}
for(auto i:dp){
max_sum = max(i,max_sum);
}
cout << max_sum;
return 0;
}

18
2019递归求阶乘.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<iostream>
using namespace std;
int func(int n){
if(n == 1){
return n;
}
else{
return n*func(n-1);
}
}
int main(){
int n;
cin >> n;
cout << func(n);
}

29
2023成绩排名.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> a;
int main() {
int n;
cin >> n;
vector<int> list(n);
for (auto i = list.begin(); i != list.end(); i++) {
cin >> *i;
}
unique(list.begin(),list.end());
sort(list.begin(), list.end(),[](int n1,int n2){
return n1>n2;
});
cin >> n;
cout << list[n - 1];
return 0;
}

29
2023括号匹配.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
stack<char> s;
string str;
cin >> str;
for(auto i = str.begin();i != str.end();i++){
switch(*i){
case '(':s.push(')');break;
case '{':s.push('}');break;
case '[':s.push(']');break;
default:
if((*i == '}')||(*i == ']')||(*i == ')')){
if(s.top() != *i){
cout << "no" << endl;
return 1;
}
s.pop();
}
}
}
cout << "yes" << endl;
return 0;
}

24
2023斐波那契数.cpp Normal file
View File

@ -0,0 +1,24 @@
#include<iostream>
#include<vector>
using namespace std;
int fbnqs(int n1,int n2,int deepth){
if(deepth == 1){
return n1 + n2;
}
else{
return fbnqs(n2,n1+n2,deepth -1);
}
}
int main(){
int n;
cin >> n;
cout << fbnqs(1,1,n - 2);
return 0;
}

18
2023求个位数.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<iostream>
using namespace std;
int main(){
int n = 0;
cin >> n;
int num = n;
for(int i =0;i < n - 1;i++){
num = num * n;
num = num%10;
}
cout << num;
return 0;
}

25
2024二元素数组.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<iostream>
using namespace std;
bool is_sushu(int n){
for(int i = 2;i*i<=n;i++){
if(n%i == 0){
return false;
}
}
return true;
}
int main(){
int n;
cin >> n;
for(int i = 0;i < n/2;i++){
if(is_sushu(i) && is_sushu(n - i)){
cout << i <<" "<< n-i << endl;
}
}
return 0;
}

33
2024体重排序.cpp Normal file
View File

@ -0,0 +1,33 @@
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int n;
pair<string,float> person;
cin >> n;
vector<pair<string,float> > list;
for(int i = 0;i < n;i++){
cin >> person.first >> person.second;
list.push_back(person);
}
sort(list.begin(),list.end(),
[](pair<string,float> p1,pair<string,float> p2){
return (p1.second < p2.second);
});
for (const auto& p : list) {
cout << p.first << " ";
}
return 0;
}

36
2024删除区间.cpp Normal file
View File

@ -0,0 +1,36 @@
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
vector<pair<int,int>> array(n);
for(auto &i:array){
cin >> i.first >> i.second;
}
sort(array.begin(),array.end(),[](pair<int,int> a,pair<int,int> b){
return a.second < b.second;
});
int last_end = -114514;
int counter = 0;
for(auto i:array){
if(last_end < i.first){
last_end = i.second;
}
else{
counter++;
}
}
cout << counter;
return 0;
}

View File

@ -0,0 +1,28 @@
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
int count = 0;
cin >> n;
vector<int> list(n);
for(int i = 0;i < n;i++){
cin >> list[i];
}
for(int i = 0;i < n;i++){
for(int j = i;j < n;j++){
if(list[i]>list[j]){
count++;
}
}
}
cout << count;
return 0;
}