郁闷死了,不知道哪里有漏洞
题目: Write a program that will remove all duplicates from a sequence of integers and print the list of unique integers occuring in the input sequence, along with the number of occurences of each.
Input
The input file will contain a sequence of integers (positive, negative, and/or zero). The input file may be arbitrarily long.
Output
The output for this program will be a sequence of ordered pairs, separated by newlines. The first element of the pair must be an integer from the input file. The second element must be the number of times that that particular integer appeared in the input file. The elements in each pair are to be separated by space characters. The integers are to appear in the order in which they were contained in the input file.
Sample Input
3 1 2 2 1 3 5 3 3 2Sample Output
3 4
1 2
2 3
5 1
link:http://acm.jlu.
我的代码:
#include <iostream>
#include <map>
#include <vector>
#include <cstdio>
using namespace std;
int main()
{
map<int,int> stut;
vector<int> index;
int yourput;
char next;
while (scanf("%d",&yourput))
{
bool isin = false;
for (unsigned i=0;i<stut.size();i++)//首先看是否在以前的index中
{
if(yourput == index[i])
{
stut[index[i]]++;
isin = true;
break;
}
else
continue;
}
if (isin == false) //不在以前的index中就创建新的index
{
index.push_back(yourput);
stut[yourput]++;
}
if (scanf("%c",&next) && next=='\n')
break;
}
for (unsigned i=0;i<stut.size();i++)
{
cout << index[i] << ' ' << stut[index[i]] << endl;
}
return 0;
}
一直wa,挺简单的一题,郁闷ing,恳求高手调试一下