简约设计の艺术

讨论软件制造过程中的艺术与工程,软件哲学

丁亮ID:DL88250
1393250次访问,排名12好友104人,关注者180
Linux、Java、C/C++,OpenSource热爱者,擅长JavaSE/JavaEE开发,熟悉JSF、EJB、Spring、JPA、OSGi等框架应用的架构,目前正在深入学习算法、OOAD、TDD以及敏捷实践。
DL88250的文章
原创 841 篇
翻译 9 篇
转载 161 篇
评论 695 篇
88250的公告





最近评论
DL88250:....
huoyuhan:谢谢
DL88250:: )
fy_kenny:
DL88250:为以后写书作点积累:)
文章分类
收藏
    相册
    Beyond
    壁纸收集
    动漫Kiss图图
    我的珍藏
    我的桌面
    CSDN专家Blog
    孟岩的专栏
    袁萌的专栏
    Ubuntu/Linux相关
    ChinaUnix
    Compiz Themes
    Compiz-Fusion
    deviantART Search
    GetDeb
    Gnome-Look
    KDE-Look
    LinuxToy
    Linux桌面中文网
    Ubuntu中文官方论坛
    Ubuntu桌面中文网
    代码示例
    C++代码示例
    HTML代码示例
    Java Code examples
    技术站点
    Apache Software
    CSDN
    Eclipse.org
    Extreme Programming
    hibernate.org
    IBM软件技术
    JavaFX Home
    JavaFX Script Reference
    JavaWorld@TW
    Java开源大全
    JBoss.org
    LEX & YACC Page
    NetBeans中文社区
    PHP 官方
    Ruby on Rails
    Ruby中文社区论坛
    SOURCEFORGE.NET
    Springframework.org
    Struts Framework
    Sun中国技术社区
    UML官方
    图书下载
    CSDN下载频道
    e 书时空
    IT e Book
    中华电脑书库
    中国 E 书网
    中国 IT 认证实验室
    中文电子书网
    偶要雷锋 - 分享社区
    我爱 e 书
    网络中国 - E 书
    网络上的博友
    吴杰博客
    老李的Blog
    我的偶像 :-)
    Alan Turing
    Bjarne Stroustrup's Homepage
    Don Knuth's Home Page
    Martin Fowler
    Richard Stallman's Home Page
    Uncle Bob (Robert C. Martin)
    我的朋友
    Eleven的专栏
    Eric.Gao的空间
    Meteor的专栏
    mmchsusan的主页
    solonote的专栏
    Vanessa的小窝
    ZhiBaoDeng的专栏
    zyofprogrammer的学习历程
    先知罗庄的专栏
    光光的Blog~
    师傅dorainm的Blog
    皮皮的空间
    秋歌的专栏
    金秋风采
    阿明的专栏
    存档
    订阅我的博客
    XML聚合  FeedSky

    原创 检查随机序列重复[C++]收藏

    新一篇: NetBeans IDE 6.1 博客大赛获奖公布! | 旧一篇: 检查随机序列重复[Java]

    /*
     * File:   Main.cpp
     * Author: 88250 <DL88250@gmail.com>, http://blog.csdn.net/DL88250
     *
     * Created on May 13, 2008, 6:25 PM
     */

    #include <iostream>
    #include <fstream>
    #include <algorithm>
    #include <vector>
    #include <time.h>

    using namespace std;

    /**
     * Check the same record in a file.
     *
     * Every record in data file is a random serial, like the followings:
     * // data file
     * 1902323484354370234844
     * 1928473090393719374
     * ....
     */

    vector<string> records; // store the data records
    vector<vector<string> > statistics; //statistics

    /**
     * Read the records from the data file which named "data.txt" into memory,
     * using a list store them.
     */
    void readRecords() {
        cout << "Get starting read records...." << endl;
        ifstream fin("data.txt");

        if (!fin) {
            cout << "Cannot open input file!" << endl;
            return;
        }

        string aLine;
        while (getline(fin, aLine)) {
            records.push_back(aLine);
        }
        fin.close();
        cout << "The amount of records: " << records.size() << endl;
    }

    /**
     * Display the data records in console.
     * @param amount display amount, start from {@link #records}'s beginning
     */
    void displayRecords(int amount) {
        if (amount < 0 || amount > records.size()) {
            cout << "The specified amount exceeds the Data records" <<
                    "size!" << endl;
        }
        cout << "Display: " << endl;
        for (int i = 0; i < amount; i++) {
            cout << records.at(i) << endl;
        }
        cout << endl;
    }

    /**
     * Display the statistic results in console.
     */
    void displayStats() {
        cout << "Statistics: " << endl;
        cout << "A amount of the same data records: " << statistics.size() << endl;
        for (int i = 0; i < statistics.size(); i++) {
            vector<string> aEqualities = statistics.at(i);
            cout << aEqualities.at(0) << " occurs " << aEqualities.size() << endl;
        }
    }
    /*
    bool greater(string s1, string s2){
        return s1.compare(s2);
    }
     */

    /**
     * Check the same data records.
     */
    void checkTheSame() {

        sort(records.begin(), records.end()); // sort them

        // displayRecords(10);
        for (int i = 0; i < records.size() - 1; i++) {
            string record1 = records.at(i);
            string record2 = records.at(i + 1);
            if (record1 == record2) {
                vector<string> equalities;
                equalities.push_back(record1);
                equalities.push_back(record2);
                statistics.push_back(equalities);
            }
        }
        displayStats();
    }

    int main(int argc, char** argv) {
        readRecords();
      
        displayRecords(10);
        checkTheSame();
        cout << "Elapsed time: " << clock() / CLOCKS_PER_SEC << endl;
        return (EXIT_SUCCESS);
    }


    发表于 @ 2008年05月15日 12:47:00|评论(loading...)|收藏

    新一篇: NetBeans IDE 6.1 博客大赛获奖公布! | 旧一篇: 检查随机序列重复[Java]

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 88250