项目二:数组分离
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
bool m;
int a[10], b[10], i, j, k = 0, n = 0;
cout << "请输入10个数:";
for (i = 0; i < 10; i++)
cin >> a[i];
{
for (i = 0; i < 10; i++)
{
m = 1;
for (j = 0; j < 10; j++)
{
if (i == j)continue;
if (a[i] == a[j])
m = 0;
}
if (m)
{
b[k] = a[i], n++, k++;
}
}
cout << "a[10]";
for (i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;
cout << "b[n]";
for (n = 0; n < k; n++)
{
cout << b[n] << " ";
}
cout << endl;
system("pause");
return 0;
}
}
项目四:字符串
#include<stdio.h>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char str[50];
int i = 0, n = 0,m=0,j=0,k=0;
cout << "输入字符串:";
gets_s(str);
while (str[i] != '\0')
{
if (str[i] >= '0'&&str[i] <= '9') n++;
else if (str[i] >= 'A'&&str[i] <= 'Z')m++;
else if (str[i] >= 'a'&&str[i] <= 'z')j++;
else k++;
i++;
}
cout << "其中的数字个数是: " << n << endl;
cout << "其中大写字母的个数是:" << m << endl;
cout << "其中小写字母的个数是:" << j << endl;
cout << "其中其他字符的个数是:" << k << endl;
system("pause");
return 0;
}