| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:郁闷死了,不知道哪里有漏洞
只看楼主 加入收藏
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
 问题点数:0 回复次数:1 
郁闷死了,不知道哪里有漏洞
题目:     
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,恳求高手调试一下
搜索更多相关主题的帖子: 漏洞 
2008-04-04 08:10
xjywc
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-1-11
收藏
得分:0 
我是菜鸟啊,不是高手,说一下啊,我还没看完呢,我感觉你的这句有毛病
while (scanf("%d",&yourput))
scanf函数返回的是输入实际赋值的个数,能进行判断吗?
2008-04-04 14:15
快速回复:郁闷死了,不知道哪里有漏洞
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015173 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved