码蹄集新手村100题答案「建议收藏」

码蹄集新手村100题答案「建议收藏」码蹄集是今年新上线的一个OJ平台,内含了100道基础题和一些百度之星的题目。由于很多题目有原创性,搜不到相关解答,因此我花了两天特将100道题目刷了一遍,目前位居榜二。码蹄集传送门:https://www.matiji.net/exam/ojquestionlist前言所有题目均能AC,不一定是最佳方法,如有其它方法,可在评论区留言讨论。1、程序设计入门#include<iostream>usingnamespacestd;intmain(){co.

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

码蹄集是今年新上线的一个OJ平台,内含了100道基础题和一些百度之星的题目。由于很多题目有原创性,搜不到相关解答,因此我花了两天特将100道题目刷了一遍,目前位居榜二。
码蹄集传送门:https://www.matiji.net/exam/ojquestionlist

排行榜截图

前言

所有题目均能AC,不一定是最佳方法,如有其它方法,可在评论区留言讨论。

1、程序设计入门

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    cout << "This is my first program!" << endl;
    cout << "Coding is fun!" << endl;
    return 0;
}

2、输入和输出整型数据

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a;
    cin >> a;
    cout << "You entered:"<< a;
    return 0;
}

3、输入和输出实型数据

在这里插入图片描述

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{ 
   
    float a;
    double b;
    cin >> a;
    cin >> b;
    cout << "You entered:" << setiosflags(ios::fixed) << setprecision(2) << a << " and " << setiosflags(ios::fixed) << setprecision(3) << b;
    return 0;
}

4、输入和输出字符型数据

在这里插入图片描述

#include <iostream>
using namespace std;

int main()
{ 
   
    int a, b;
    scanf_s("%d,%d", &a,&b);
    cout << a << "+" << b << "=" << a+b << endl;
    cout << a << "-" << b << "=" << a-b;
    
    return 0;
}

5、整数运算

在这里插入图片描述

#include <iostream>
using namespace std;

int main()
{ 
   
    int a, b;
    scanf("%d,%d", &a,&b);
    cout << a << "+" << b << "=" << a+b << endl;
    cout << a << "-" << b << "=" << a-b;
    
    return 0;
}

6、实型数运算

在这里插入图片描述

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{ 
   
    double a, b;
    cin >> a >> b;
    cout << setiosflags(ios::fixed) << setprecision(6) << a << "*" << setiosflags(ios::fixed) << setprecision(6) << b << "=" << setiosflags(ios::fixed) << setprecision(6) << a * b << endl;
    cout << setiosflags(ios::fixed) << setprecision(6) << a << "/" << setiosflags(ios::fixed) << setprecision(6) << b << "=" << setiosflags(ios::fixed) << setprecision(6) << a / b;
    
    return 0;
}

7、求余

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << a << "%" << b << "=" << a%b << endl;
    cout << c << "%" << d << "=" << c%d;
    return 0;
}

8、各种类型长

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    cout << "Size of int: " << sizeof(int) << " bytes" << endl;
    cout << "Size of float: " << sizeof(float) << " bytes" << endl;
    cout << "Size of double: " << sizeof(double) << " bytes" << endl;
    cout << "Size of char: " << sizeof(char) << " byte";

    return 0;
}

9 、关键字long

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    cout << "Size of int = " << sizeof(int) << " bytes" << endl;
    cout << "Size of long int = " << sizeof(long int) << " bytes" << endl;
    cout << "Size of long long int = " << sizeof(long long int) << " bytes" << endl;
    cout << "Size of double = " << sizeof(double) << " bytes" << endl;
    cout << "Size of long double = " << sizeof(long double) << " bytes" ;

    return 0;
}

10、交换

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a,b;
    cin >> a >> b;
    cout << b << " " << a;
    return 0;
}

11、求圆面积和周长

在这里插入图片描述

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
#define pi 3.1415926

int main()
{ 
   
    double r;            
    cin >> r;
    cout << "Area=" << setiosflags(ios::fixed) << setprecision(6) << pi * r * r << endl;
    cout << "Circumference=" << setiosflags(ios::fixed) << setprecision(6) << 2 * pi * r;
    return 0;
}

12、求矩形面积和周长

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    double a, b;
    cin >> a >> b;
    printf("Area=%.6f\n", a * b);
    printf("Perimeter=%.6f", a * 2 + b * 2);
    return 0;
}

13、椭圆计算

在这里插入图片描述

#include <iostream>
#include <iomanip>

using namespace std;
# define pi 3.1415926
int main( )
{ 
   
    double a,b;
    cin >> a >> b;
    cout << "Area = " << setiosflags(ios::fixed) << setprecision(6) << pi * a * b;
    
    return 0;
}

14、圆锥的表面积

在这里插入图片描述

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

# define pi 3.1415926
int main()
{ 
   
    double r, h, area;
    cin >> r >> h;
    area = pi * r * (r + sqrt(pow(r, 2) + pow(h, 2)));
    cout << "Surface area=" << setiosflags(ios::fixed) << setprecision(2) << area;
    return 0;
}

15、三角形面积

在这里插入图片描述

#include <iostream>
#include<iomanip>
using namespace std;

int main( )
{ 
   
    float a,b;
    cin >> a >> b;
    cout << "Area=" << setiosflags(ios::fixed) << setprecision(2) << 0.5 * a * b;
    return 0;
}

16、平方根和对数值

在这里插入图片描述

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{ 
   
    double a;
    cin >> a;
    cout << setiosflags(ios::fixed) << setprecision(2) << sqrt(a) << " " << setiosflags(ios::fixed) << setprecision(2) << log(a) << " " << setiosflags(ios::fixed) << setprecision(2) << log10(a);
    return 0;
}

17、坐标的转换

在这里插入图片描述

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#define pi 3.1415926

int main()
{ 
   
    float x, y;
    cin >> x >> y;
    cout << setiosflags(ios::fixed) << setprecision(1) << sqrt(pow(x, 2) + pow(y, 2)) << " " << setiosflags(ios::fixed) << setprecision(1) << atan(y/x)*180/pi;
    return 0;
}

18、分期付款

在这里插入图片描述

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main( )
{ 
   
    double p ,r , n;
    cin >> p >> r >> n;
    r = r/(12*100);
    double rate = p * r * pow(1+r,n)/(pow(1+r,n)-1);
    cout << setiosflags(ios::fixed) << setprecision(1) << rate;
    return 0;
}

19、极坐标到笛卡尔坐标的转换

在这里插入图片描述

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define pi 3.1415926
int main()
{ 
   
    double r, theta;
    cin >> r >> theta;
    double x = r * cos(theta * pi / 180);
    double y = r * sin(theta * pi / 180);
    cout << setiosflags(ios::fixed) << setprecision(2) << x << "," << setiosflags(ios::fixed) << setprecision(2) << y;
    return 0;
}

20、公里转换成米

在这里插入图片描述

#include <iostream>
#include <iomanip>
using namespace std;

int main( )
{ 
   
    double a;
    cin >> a;
    cout << setiosflags(ios::fixed) << setprecision(2) << a << "公里="<< setiosflags(ios::fixed) << setprecision(2) << a*1000 << "米";
    return 0;
}

21、和10相比

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a;
    cin >> a;
    if (a<10)
    { 
   
        cout << a << "小于10";
    }
    else if (a == 10)
    { 
   
        cout << a << "等于10";
    }
    else
    { 
   
        cout << a << "大于10";
    }
    return 0;
}

22、成绩评语

在这里插入图片描述

#include <iostream>
using namespace std;

int main()
{ 
   
    char a;
    cin >> a;
    if (a == 'A')
    { 
   
        cout << "Excellent";
    }
    else if (a == 'B')
    { 
   
        cout << "Well done";
    }
    else if (a == 'C')
    { 
   
        cout << "You passed";
    }
    else if (a == 'D')
    { 
   
        cout << "Better luck next time";
    }
    else
    { 
   
        cout << "Invalid grade";
    }

    return 0;
}

23、元音

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    char a;
    cin >> a;
    if (a == 'A' or a == 'E' or a =='I' or a == 'O' or a == 'U') cout << "Y";
    else cout << "N";
    return 0;
}

24、大小写的转换

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    char a;
    cin >> a;
    if (a >= 'a' & a <= 'z')
    { 
   
        cout << char(a - 32);
    }
    else if (a >= 'A' & a <= 'Z')
    { 
   
        cout << char(a + 32);
    }
    else
    { 
   
        cout << a;
    }
    return 0;
}

25、最小值

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a,b;
    cin >> a >> b;
    if (a > b) cout << b;
    else cout << a;
    return 0;
}

26、最大值

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a,b;
    cin >> a >> b;
    if (a > b) cout << a;
    else cout << b;
    return 0;
}

27、中庸之道

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{ 
   
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    cout << v[1];
    return 0;
}

28、三人同行

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{ 
   
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    cout << v[2];
    return 0;
}

29、偶数还是奇数

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a;
    cin >> a;
    if (a % 2 == 0) cout << "Y";
    else cout << "N";
    return 0;
}

30、闰年

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int year;
    cin >> year;
    if((year%4==0 && year%100!=0) | (year%400 == 0)) cout << "Y";
    else cout << "N";
    return 0;
}

31、while循环

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int i = 0;
    while ( i < 8 )
    { 
   
        cout << i << " ";
        i ++;
    }
    return 0;
}

32、do-while循环

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    int n;
    cin >> n;
    do 
    { 
   
        cout << n << " ";
        n--;
    } while (n != 0);
    return 0;
}

33、阶乘

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a,b,c;
    cin >> a;
    c = a;
    b = 1;
    while (a != 1)
    { 
   
        b = b * a;
        a --;
    }
    cout << c << "!=" << b;
    return 0;
}

34、 累加和

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a = 1;
    int sum = 0;
    while (a != 11)
    { 
   
        sum += a;
        a++;
    }
    cout << sum;
    return 0;
}

35、斐波那契数列

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    cout << "1" << " " << "1" << " " << "2" << " " << "3" << " " << "5" << " " << "8" << " " << "13" << " " << "21" << " " << "34" << " "<< "55";
    return 0;
}

36、回文数字

在这里插入图片描述

#include <iostream>
#include<string>

using namespace std;

int main()
{ 
   
    string a;
    cin >> a;
    int l = a.size();
    bool flag = true;
    for (int i = 0; i <= l/2; i++)
    { 
   
        if (a[i] != a[l - i - 1]) flag = false;
    }
    if (flag == true) cout << "Y";
    else cout << "N";

    return 0;
}

37、数字和

在这里插入图片描述

#include <iostream>
#include <string>

using namespace std;

int main()
{ 
   
    string a;
    cin >> a;
    int sum = 0;
    for (int i = 0; i < a.size(); i++)
    { 
   
        sum += int(a[i]-'0');
    }
    cout << sum;
    return 0;
}

38、平均值

在这里插入图片描述

#include <iostream>
#include <iomanip>
using namespace std;

int main( )
{ 
   
    float n;
    float a[100];
    float sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    { 
   
        cin >> a[i];
        sum += a[i];
    }
    cout << setiosflags(ios::fixed) << setprecision(2) << sum/n;

    return 0;
}

39、自恋性数

在这里插入图片描述

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{ 
   
    string a;
    cin >> a;
    int b = atoi(a.c_str());
    int sum = 0;
    for (int i = 0; i < a.size(); i++)
    { 
   
        sum += pow(int(a[i]-'0'), 3);
    }
    if (b == sum) cout << "Y";
    else cout << "N";
    return 0;
}

40、输出n以内自恋性数

在这里插入图片描述

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

bool isams(int a)
{ 
   
    int c = a;
    int b = c % 10;
    vector<int> d;
    int sum = 0;
    while (c != 0)
    { 
   
        d.push_back(b);
        c = c / 10;
        b = c % 10;
    }
    for (int i = 0; i < d.size(); i++)
    { 
   
        sum += pow(d[i], 3);
    }
    if (a == sum) return true;
    else return false;
}
int main()
{ 
   
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    { 
   
        if (isams(i) == true) cout << i << " ";
    }
    return 0;
}

41、百钱买百猫

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    for (int i = 0; i <= 12; i++)
    { 
   
        for (int j = 25; j >= 0; j--)
        { 
   
            for (int k = 0; k <= 33; k++)
            { 
   
                if ((i + j + k * 3 == 100) && (5 * i + 3 * j + k == 100))
                { 
   
                    cout << "公猫=" << i << " 母猫=" << j << " 小猫=" << k*3 << endl;
                }
            }
        }
    }
    return 0;
}

42、F字矩阵

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int n;
    cin >> n;
    for (int i = 0 ; i < n ; i++)
    { 
   
        for (int j = 0 ; j < n ; j++)
        { 
   
            cout << "F" << " ";
        }
        cout << endl;
    }
    return 0;
}

43、F字三角

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int n;
    cin >> n;
    for (int i = 0 ; i < n ; i++)
    { 
   
        for (int j = 0 ; j < 2*i + 1 ; j++)
        { 
   
            cout << "F";
        }
        cout << endl;
    }
    return 0;
}

44、倒三角

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int n;
    cin >> n;
    for (int i = 0 ; i < n ; i++)
    { 
   
        for (int j = n ; j > i ; j--)
        { 
   
            cout << "F";
        }
        cout << endl;
    }
    return 0;
}

45、金字塔

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
	{ 
   
		for(int j=1;j<=n-i;j++)
		{ 
   
			cout<<" ";
		}
		for(int j=1;j<=2*i-1;j++)
		{ 
   
			cout<<"W";
		}
		cout<<endl;
	}
    return 0;
}

46、倒金字塔

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    { 
   
        for (int j = n - i + 1; j > 0; j--)
        { 
   
            cout << " ";
        }
        for (int k = 0; k < i - 1; k++)
        { 
   
            cout << "W ";
        }
        cout << endl;
    }
    for (int i = 1; i <= n; ++i)
    { 
   
        for (int k = 0; k < i - 1; k++)
        { 
   
            cout << " ";
        }
        for (int j = n - i + 1; j > 0; j--)
        { 
   
            cout << "W ";
        }
        cout << endl;
    }
    return 0;
}

47、菱形

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++)
    { 
   
        for (int j = 1; j <= n - i + 1; j++)
        { 
   
            cout << " ";
        }
        for (int k = 1; k <= i - 1; k++)
        { 
   
            cout << "W ";
        }
        cout << endl;
    }
    for (int i = 1; i <= n; ++i)
    { 
   
        for (int k = 0; k < i - 1; k++)
        { 
   
            cout << " ";
        }
        for (int j = n - i + 1; j > 0; j--)
        { 
   
            cout << "W ";
        }
        cout << endl;
    }
    return 0;
}

48、沙漏

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    { 
   
        for (int k = 0; k < i - 1; k++)
        { 
   
            cout << " ";
        }
        for (int j = n - i + 1; j > 0; j--)
        { 
   
            cout << "W ";
        }
        cout << endl;
    }
    for (int i = 2; i <= n+1; ++i)
    { 
   
        for (int j = 1; j <= n - i + 1; j++)
        { 
   
            cout << " ";
        }
        for (int k = 1; k <= i - 1; k++)
        { 
   
            cout << "W ";
        }
        cout << endl;
    }
    return 0;
}

49、乘法表

在这里插入图片描述

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{ 
   
    int n;
	int i, j;
    cin >> n;
	for (j = 1; j <= n; j++)
	{ 
   
		for (i = 1; i <= j; i++)
		{ 
   
			printf("%d*%d=%d", j, i, i * j);
			if (j == i)
			{ 
   
				printf("\n");
			}
			else
			{ 
   
				if ((i * j) / 10 == 0)
				{ 
   
					printf(" ");
				}
				else
				{ 
   
					printf(" ");
				}
			}
		}
	}


    return 0;
}

50、字母统计

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main()
{ 
   
    string n;
    getline(cin ,n);
    int sum = 0;
    for (int i = 0 ; i < n.size(); i++)
    { 
   
        if ((n[i] >= 'a' & n[i] <= 'z') | (n[i] >= 'A' & n[i] <= 'Z')) sum++;
    }
    cout << sum;
    return 0;
}

51、用函数求阶乘

在这里插入图片描述

#include <iostream>

using namespace std;

int fact(int x)
{ 
   
    int sum = 1;
    while (x >= 1)
    { 
   
        sum *= x;
        x --;
    }
    return sum;
}
int main( )
{ 
   
    int x;
    cin >> x;
    cout << fact(x);
    return 0;
}

52、用函数求和

在这里插入图片描述

#include <iostream>

using namespace std;

int add(int x, int y)
{ 
   
    return x + y;
}

int main( )
{ 
   
    int a, b;
    scanf("%d,%d",&a,&b);
    cout << add(a,b);
    return 0;
}

53、pi的近似值

在这里插入图片描述

#include <iostream>
#include<cmath>
using namespace std;

double Fun()
{ 
   
    double s = 1, pi = 0, n = 1, t = 1;
	while (fabs(t) > 1e-6)
		pi = pi + t, n = n + 2, s = -s, t = s / n;
    return pi * 4;
}

int main( )
{ 
   
    double res = Fun();
    printf("%.2f",res);
    return 0;
}

54、用函数求最大值

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int sum(vector<int> a)
{ 
   
    sort(a.begin(), a.end(), greater<int>());
    return a[0];
}

int main()
{ 
   
    int a, b, c, d;
    vector<int> v;
    cin >> a >> b >> c >> d;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    cout << sum(v);
    return 0;
}

55、用函数求最小值

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int sum(vector<int> a)
{ 
   
    sort(a.begin(), a.end());
    return a[0];
}

int main()
{ 
   
    int a, b, c, d;
    vector<int> v;
    cin >> a >> b >> c >> d;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    cout << sum(v);
    return 0;
}

56、递归求工资

在这里插入图片描述

#include <iostream>

using namespace std;

int money (int n)
{ 
   
    if (n==1) return 1000;
    else return 200 + money(n-1);
}
int main( )
{ 
   
    int n ;
    cin >> n;
    cout << money(n);
    return 0;
}

57、n次方

在这里插入图片描述

#include <iostream>
#include <cmath>
using namespace std;

int fun(int m , int n)
{ 
   
    return pow(m,n);
}
int main( )
{ 
   
    int m , n;
    cin >> m >> n;
    cout << fun(m,n);
    return 0;
}

58、用函数判断素数

在这里插入图片描述

#include <iostream>

using namespace std;

bool fun(int n)
{ 
   
    bool flag = true;
    for (int i = 2 ; i < n/2 + 1 ; i ++)
    { 
   
        if (n % i == 0 ) flag = false;
    }
    return flag;
}
int main( )
{ 
   
    int n ;
    cin >> n;
    bool flag = fun(n);
    if (n == 1) cout << "N";
    else
    { 
   
        if (flag == true) cout << "Y";
        else cout << "N";
    }

    return 0;
}

59、用函数计算公式

在这里插入图片描述

#include <iostream>

using namespace std;

int fun (int n)
{ 
   
    int sum = 0;
    for (int i=1;i<=n;i=i+3)
    { 
   
        sum += i;
    }
    return sum;
}
int main( )
{ 
   
    int n;
    cin >> n;
    cout << fun(n);
    return 0;
}

60、平方和

在这里插入图片描述

#include <iostream>

using namespace std;

int fun (int n)
{ 
   
    int sum = 0;
    for (int i=1; i<=n; i++)
    { 
   
        sum+= i*i;
    }
    return sum;
}
int main( )
{ 
   
    int n;
    cin >> n;
    cout << fun(n);
    return 0;
}

61、逆序输出数组

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void myprint(int v)
{ 
   
    cout << v << " ";
}
int main()
{ 
   
    vector <int> v;
    int n;
    while (cin >> n)
    { 
   
        v.push_back(n);
    }
    reverse(v.begin(), v.end());
    for_each(v.begin(), v.end(), myprint);
    return 0;
}

62、奇数项

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a[10];
    for (int i = 0; i<10 ; i++)
    { 
   
        cin >> a[i];
    }
    for (int j = 1; j <10 ; j=j+2)
    { 
   
        cout << a[j] << " ";
    }
    return 0;
}

63、偶数项和偶数值

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a[10];
    for (int i = 0; i<10 ; i++)
    { 
   
        cin >> a[i];
    }
    for (int j = 0; j <10 ; j=j+2)
    { 
   
        if (a[j] % 2 ==0)cout << a[j] << " ";
    }
    return 0;
}

64、李代桃僵

在这里插入图片描述

#include <iostream>
#include <algorithm>
using namespace std;

int main( )
{ 
   
    int v[10];
    int a;
    int n,m;
    for(int i = 0 ; i<10;i++)
    { 
   
        cin >> v[i];
    }
    cin >> n >> m;
    for (int j = 0 ; j<10;j++)
    { 
   
        if (v[j]==n) v[j]=m;
    }
    for (int i = 0 ; i < 10 ; i++)
    { 
   
        cout << v[i] << " ";
    }

    return 0;
}

65、删除指定元素

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int n;
    int a[100];
    int b;
    cin >> n;
    for (int i = 0 ; i < n ; i++)
    { 
   
        cin >> a[i];
    }
    cin >> b;
    for (int j = b ; j < n ; j++)
    { 
   
        a [j-1] = a[j];
    }
    for (int i = 0 ; i < n - 1; i++)
    { 
   
        cout << a[i] << " ";
    }
    return 0;
}

66、删除指定元素2

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int n;
    int a[100];
    int b;
    cin >> n;
    for (int i = 0 ; i < n ; i++)
    { 
   
        cin >> a[i];
    }
    cin >> b;

    for (int j = 0; j < n ; j++)
    { 
   
        if (a[j] == b) 
        { 
   
            a[j] = -100;
        }
    }
    for (int i = 0 ; i < n; i++)
    { 
   
        if (a[i] != -100) cout << a[i] << " ";
    }
    return 0;
}

67、数组最值

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a[100];
    int n;
    cin >> n;
    for (int i=0;i<n;i++)
    { 
   
        cin >> a[i];
    }
    int max = a[0];
    int min = a[0];
    for (int j=1;j<n;j++)
    { 
   
        if (a[j] < min) min = a[j];
        if (a[j] > max) max = a[j];
    }
    cout << max << " " << min;
    return 0;
}

68、元素和

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a[100];
    int n;
    int sum = 0;
    cin >> n;
    for (int i=0;i<n;i++)
    { 
   
        cin >> a[i];
        sum += a[i];
    }
    cout << sum;
    return 0;
}

69、排序吧

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{ 
   
    int num;
    int a[10];
    cin >> num;
    for (int i = 0; i < num; i++)
    { 
   
        cin >> a[i];
    }

    for (int i = 0; i < num; i++)
    { 
   
        for (int j = i + 1; j < num; j++)
        { 
   
            if (a[i] > a[j])
            { 
   
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    
    for (int i = 0; i < num; i++)
    { 
   
        cout << a[i] << " ";
    }



    return 0;
}

70、查重

在这里插入图片描述

#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main( )
{ 
   
    int n;
    int a[100];
    int b[100]={ 
   0};
    cin >> n;
    for (int i=0; i<n;i++)
    { 
   
        cin >> a[i];
        b[a[i]] ++;
        if (b[a[i]] > 1)
        { 
   
            b[a[i]]--;
            a[i] = -100;
        }
    }
    
    for (int j=0; j<n ;j++)
    { 
   
        if (a[j]!=-100) cout << a[j] << " ";
    }


    return 0;
}

71、反转

在这里插入图片描述

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main( )
{ 
   
    string s;
    getline(cin ,s);
    reverse(s.begin(),s.end());
    cout << s;
    return 0;
}

72、字符串数组

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s1,s2,s3;
    getline(cin, s1);
    getline(cin, s2);
    getline(cin, s3);
    cout << s1 << endl;
    cout << s2 << endl;
    cout << s3 << endl;
    return 0;
}

73、字符串长度函数

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s;
    getline(cin,s);
    cout << s.size() <<" " << 80;
    return 0;
}

74、字符串比较函数

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    int ret = s1.compare(s2);
    cout << ret;
    return 0;
}

75、字符串输入输出方法1

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    cout << s2;
    return 0;
}

76、字符串输入输出方法2

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    cout << s2;
    return 0;
}

77、字符串输入输出方法3

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    cout << s2;
    return 0;
}

78、字符串输入输出方法4

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s;
    getline(cin,s);
    cout << s;
    return 0;
}

79、字符串连接函数

在这里插入图片描述

#include<stdio.h>
#include<string.h>
int main()
{ 
   
    char a[20]={ 
   '
#include<stdio.h>
#include<string.h>
int main()
{ 

char a[20]={ 
'\0'},b[10]={ 
'\0'};
int i,la,lb;
scanf("%s",&a);
scanf("%s",&b);
la=strlen(a);
lb=strlen(b);
for(i=0;i<lb;i++)
a[la+i]=b[i];
for(i=0;i<(la+lb);i++)
printf("%c",a[i]);
}
'
},b[10]={ '
#include<stdio.h>
#include<string.h>
int main()
{ 

char a[20]={ 
'\0'},b[10]={ 
'\0'};
int i,la,lb;
scanf("%s",&a);
scanf("%s",&b);
la=strlen(a);
lb=strlen(b);
for(i=0;i<lb;i++)
a[la+i]=b[i];
for(i=0;i<(la+lb);i++)
printf("%c",a[i]);
}
'
}; int i,la,lb; scanf("%s",&a); scanf("%s",&b); la=strlen(a); lb=strlen(b); for(i=0;i<lb;i++) a[la+i]=b[i]; for(i=0;i<(la+lb);i++) printf("%c",a[i]); }

80、字符串复制函数

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string a;
    cin >> a;
    cout << a;
    return 0;
}

81、变量和它的指针

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a;
    int *p;
    cin >> a;
    p = &a;
    cout << *p;
    return 0;
}

82、用指针交换两个数

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    int a, b;
    cin >> a >> b;
    int* p1;
    int* p2;
    int temp;
    p1 = &a;
    p2 = &b;
    temp = *p1;
    *p1 = *p2;
    *p2 = temp;
    cout << *p1 << " " << *p2;
    return 0;
}

83、顺序输出

在这里插入图片描述

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void myprint(int v)
{ 
   
    cout << v << " ";
}
int main( )
{ 
   
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(),v.end());
    for_each(v.begin(),v.end(),myprint);
    return 0;
}

84、实型指针

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    float a;
    cin >> a;
    float *p;
    p = &a;
    printf("%.6f",*p);
    return 0;
}

85、字符型指针

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    char a;
    char *p =&a;
    cin >> a;
    cout << *p;
    return 0;
}

86、指向一维数组的指针

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string a;
    getline(cin, a);
    cout << a;
    return 0;
}

87、指向字符串的指针

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string s;
    getline(cin,s);
    int n;
    cin >> n;
    cout << s[n-1];
    return 0;
}

88、二维数组行指针

在这里插入图片描述

#include <iostream>

using namespace std;

int main()
{ 
   
    int a[3][3];
    int(*p)[3] = a;

    for (int i = 0; i < 3; i++)
    { 
   
        for (int j = 0; j < 3; j++)
        { 
   
            cin >> a[i][j];
            cout << *(p[i] + j);
            cout << " ";
        }
        cout << endl;
    }

    return 0;
}

89、二维数组列指针

在这里插入图片描述

#include <iostream>
#include<iomanip>
using namespace std;

int a[4][4];
int* p = a[0];
int main()
{ 
   
    for (int i = 0; i < 4; i++)
    { 
   
        for (int j = 0; j < 4; j++)
        { 
   
            cin >> a[i][j];
            cout << setw(2) << *(p + i * 4 + j) << " ";
        }
        cout << endl;
    }
    return 0;
}

90、函数指针

在这里插入图片描述

#include <iostream>

using namespace std;

int main( )
{ 
   
    int a , b;
    cin >> a >> b;
    cout << a+b << " " << a-b;
    return 0;
}

91、新生命

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

int main( )
{ 
   
    string a;
    getline(cin ,a);
    cout << a;
    return 0;
}

92、幼儿园

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct baby
{ 
   
    string name;
    int age;
    string sex;
};

int main()
{ 
   
    string a, c;
    int b;
    struct baby bb1;
    cin >> a >> b >> c;
    bb1.name = a;
    bb1.age = b;
    bb1.sex = c;

    struct baby bb2;
    cin >> a >> b >> c;
    bb2.name = a;
    bb2.age = b;
    bb2.sex = c;
    
    struct baby bb3;
    cin >> a >> b >> c;
    bb3.name = a;
    bb3.age = b;
    bb3.sex = c;

    struct baby bb4;
    cin >> a >> b >> c;
    bb4.name = a;
    bb4.age = b;
    bb4.sex = c;

    struct baby bb5;
    cin >> a >> b >> c;
    bb5.name = a;
    bb5.age = b;
    bb5.sex = c;

    cout << bb1.name << " " << bb1.age << " " << bb1.sex << " ";
    cout << bb2.name << " " << bb2.age << " " << bb2.sex << " ";
    cout << bb3.name << " " << bb3.age << " " << bb3.sex << " ";
    cout << bb4.name << " " << bb4.age << " " << bb4.sex << " ";
    cout << bb5.name << " " << bb5.age << " " << bb5.sex << " ";
    return 0;
    
}

93、龙族

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct dragon
{ 
   
    string name;
    string color;
    int attack;
};

int main()
{ 
   
    string a, b;
    int c;
    struct dragon bb1;
    cin >> a >> b >> c;
    bb1.name = a;
    bb1.color = b;
    bb1.attack = c;

    struct dragon bb2;
    cin >> a >> b >> c;
    bb2.name = a;
    bb2.color = b;
    bb2.attack = c;

    struct dragon bb3;
    cin >> a >> b >> c;
    bb3.name = a;
    bb3.color = b;
    bb3.attack = c;


    cout << bb1.name << " " << bb1.color << " " << bb1.attack << endl;
    cout << bb2.name << " " << bb2.color << " " << bb2.attack << endl;
    cout << bb3.name << " " << bb3.color << " " << bb3.attack;
    return 0;

}

94、排兵布阵

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct dragon
{ 
   
    string name;
    string color;
    int attack;
};

int main()
{ 
   
    string a, b;
    int c;
    dragon bb1;
    cin >> a >> b >> c;
    bb1.name = a;
    bb1.color = b;
    bb1.attack = c;

    dragon bb2;
    cin >> a >> b >> c;
    bb2.name = a;
    bb2.color = b;
    bb2.attack = c;

    if (bb1.attack < bb2.attack)
    { 
   
        dragon temp = bb1;
        bb1 = bb2;
        bb2 = temp;
    }
    cout << bb1.name << " " << bb1.color << " " << bb1.attack << endl;
    cout << bb2.name << " " << bb2.color << " " << bb2.attack ;

    return 0;

}

95、谁是先锋

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct man
{ 
   
    string name;
    int attack;
};

void sort(man mans[],  int n)
{ 
   
    for (int i = 0; i < n; i++)
    { 
   
        for (int j = i; j < n; j++)
        { 
   
            if (mans[i].attack < mans[j].attack)
            { 
   
                man temp = mans[i];
                mans[i] = mans[j];
                mans[j] = temp;
            }
        }
    }
}
int main()
{ 
   
    string a;
    int b;
    man mans[4];
    cin >> a >> b;
    mans[0].name = a;
    mans[0].attack = b;
    cin >> a >> b;
    mans[1].name = a;
    mans[1].attack = b;
    cin >> a >> b;
    mans[2].name = a;
    mans[2].attack = b;
    cin >> a >> b;
    mans[3].name = a;
    mans[3].attack = b;
    sort(mans, 4);
    cout << mans[0].name << " " << mans[0].attack;

    return 0;
}

96、谁是胆小鬼

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct man
{ 
   
    string name;
    int attack;
};

void sort(man mans[],  int n)
{ 
   
    for (int i = 0; i < n; i++)
    { 
   
        for (int j = i; j < n; j++)
        { 
   
            if (mans[i].attack > mans[j].attack)
            { 
   
                man temp = mans[i];
                mans[i] = mans[j];
                mans[j] = temp;
            }
        }
    }
}
int main()
{ 
   
    string a;
    int b;
    man mans[4];
    cin >> a >> b;
    mans[0].name = a;
    mans[0].attack = b;
    cin >> a >> b;
    mans[1].name = a;
    mans[1].attack = b;
    cin >> a >> b;
    mans[2].name = a;
    mans[2].attack = b;
    cin >> a >> b;
    mans[3].name = a;
    mans[3].attack = b;
    sort(mans, 4);
    cout << mans[0].name << " " << mans[0].attack;

    return 0;
}

97、依依学编程

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct book
{ 
   
    string zl;
    string sm;
    int jg;
};

void printbk(book bk[] , int n)
{ 
   
    cout << bk[n].zl << " " << bk[n].sm << " " << bk[n].jg << endl;
}


int main( )
{ 
   
    string a,b;
    int c;
    book bk[3];
    cin >> a >> b >> c;
    bk[0].zl = a;
    bk[0].sm = b;
    bk[0].jg = c;
    cin >> a >> b >> c;
    bk[1].zl = a;
    bk[1].sm = b;
    bk[1].jg = c;
    cin >> a >> b >> c;
    bk[2].zl = a;
    bk[2].sm = b;
    bk[2].jg = c;
    for (int i = 0 ; i < 3 ; i++)
    { 
   
        int ret = bk[i].zl.compare("c");
        if (ret == 0)printbk(bk, i);
    }




    return 0;
}

98、编程好难

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

struct book
{ 
   
    string zl;
    string sm;
    int jg;
};

void sort (book bk[], int n)
{ 
   
    for (int i = 0 ;i < n ; i++)
    { 
   
        for (int j = i ; j < n ; j++)
        { 
   
            if (bk[i].jg > bk[j].jg)
            { 
   
                book temp = bk[i];
                bk[i] = bk[j];
                bk[j] = temp;
            }
        }
    }
}

int main( )
{ 
   
    string a,b;
    int c;
    book bk[3];
    cin >> a >> b >> c;
    bk[0].zl = a;
    bk[0].sm = b;
    bk[0].jg = c;
    cin >> a >> b >> c;
    bk[1].zl = a;
    bk[1].sm = b;
    bk[1].jg = c;
    cin >> a >> b >> c;
    bk[2].zl = a;
    bk[2].sm = b;
    bk[2].jg = c;
    sort (bk, 3);
    cout << bk[0].zl << " " << bk[0].sm << " " << bk[0].jg;




    return 0;
}

99、长者

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

class person
{ 
   
public:
    string xm;
    int age;
};

void sort(person bk[], int n)
{ 
   
    for (int i = 0; i < n; i++)
    { 
   
        for (int j = i; j < n; j++)
        { 
   
            if (bk[i].age < bk[j].age)
            { 
   
                person temp = bk[i];
                bk[i] = bk[j];
                bk[j] = temp;
            }
        }
    }
}

int main()
{ 
   
    string a;
    int b;
    person bk[5];
    cin >> a >> b;
    bk[0].xm = a;
    bk[0].age = b;
    cin >> a >> b;
    bk[1].xm = a;
    bk[1].age = b;
    cin >> a >> b;
    bk[2].xm = a;
    bk[2].age = b;
    cin >> a >> b;
    bk[3].xm = a;
    bk[3].age = b;
    cin >> a >> b;
    bk[4].xm = a;
    bk[4].age = b;
    sort(bk, 5);
    cout << bk[0].xm << " " << bk[0].age;




    return 0;
}

100、幼者

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;

class person
{ 
   
public:
    string xm;
    int age;
};

void sort(person bk[], int n)
{ 
   
    for (int i = 0; i < n; i++)
    { 
   
        for (int j = i; j < n; j++)
        { 
   
            if (bk[i].age > bk[j].age)
            { 
   
                person temp = bk[i];
                bk[i] = bk[j];
                bk[j] = temp;
            }
        }
    }
}

int main()
{ 
   
    string a;
    int b;
    person bk[5];
    cin >> a >> b;
    bk[0].xm = a;
    bk[0].age = b;
    cin >> a >> b;
    bk[1].xm = a;
    bk[1].age = b;
    cin >> a >> b;
    bk[2].xm = a;
    bk[2].age = b;
    cin >> a >> b;
    bk[3].xm = a;
    bk[3].age = b;
    cin >> a >> b;
    bk[4].xm = a;
    bk[4].age = b;
    sort(bk, 5);
    cout << bk[0].xm << " " << bk[0].age;

    return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/184613.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号