首先看题
http://ybt.ssoier.cn:8088/problem_show.php?pid=1102
1102:与指定数字相同的数的个数【输入】输入包含三行: 第一行为nn,表示整数序列的长度(n≤100n≤100); 第二行为nn个整数,整数之间以一个空格分开; 第三行包含一个整数,为指定的数字mm。 【输出】输出为n个数中与m相同的数的个数。 下面是代码 #include <iostream> #include <vector> using namespace std; int main(void) { vector <int>v;//声明vector容器 int n = 0;//保存总数 int m = 0;//保存特殊数 int count = 0;//保存次数 cin >> n;//输入 for (int i = 0; i < n; ++i)//通过尾插的方式输入 { int temp = 0;//声明临时变量中转 cin >> temp;//输入 v.push_back(temp);//通过尾插保存 } cin >> m;//输入特殊数 for (int i = 0; i < n; ++i)//判断 { if (m==v[i])//判断是否相符 { ++count;//次数增减 } } cout << count << endl;//输出结果 return 0; } 好了 别忘了把该点的点了 |