删除整数序列中某个整数
有一个整数序列(可能有重复的整数),现删除指定的某一个整数,输出删除指定数字之后的序列,序列中未被删除数字的前后位置没有发生改变。
数据范围:序列长度和序列中的值都满足 1≤�≤501≤n≤50
输入描述:
第一行输入一个整数(0≤N≤50)。
第二行输入N个整数,输入用空格分隔的N个整数。
第三行输入想要进行删除的一个整数。
输出描述:
输出为一行,删除指定数字之后的序列。
示例1
输入:
6 1 2 3 4 5 9 4
复制输出:
1 2 3 5 9
复制
示例2
输入:
5 1 2 3 4 6 5
复制输出:
1 2 3 4 6
代码:
#include <cstdint>
#include <iostream>
using namespace std;
int main()
{
int n, m;
cin >> n;
int a[100];
for (int i = 0; i < n; i++) cin >> a[i];
cin >> m;
int k, d = 0;
for (k = 0; k < n; k++)
{
if (a[k] == m) d++;
}
for (int i = 0; i < d; i++)
{
for (k = 0; k < n; k++)
{
if (a[k] == m) break;
}
for (int j = k; j < n; j++)
{
a[j] = a[j + 1];
}
}
for (int g = 0; g < n - d; g++) cout << a[g] << " ";
return 0;
}
哥德巴赫猜想猜想
代码:
#include<iostream>
using namespace std;
int num(int x)
{
int k = 0;
if (x == 2) k=0;
else if (x == 1 || x == 0) k++;
else
{
for (int i = 2; i < x; i++)
{
if (x % i == 0) k++;
}
}
return k;
}
void Goldbach(int x)
{
for (int i = 0; i <= x/2; i++)
{
int m= num(i);
if (m == 0)
{
for (int j = 0; j <= x; j++)
{
int n = num(j);
if (n == 0)
{
if (x == i + j)
cout << x << "=" << i << "+" << j << endl;
}
else continue;
}
}
else continue;
}
}
int main()
{
int a;
cin >> a;
Goldbach(a);
return 0;
}
继承
继承的好处:减少重复代码。
一般写法为:class basepage{};//公共信息类
class 类名:Public basepage{};
继承的方式:
1、公共继承
2、私有继承
3、保护继承