[Вопрос] Нужна не большая помощь.

Discussion in 'Болталка' started by Jokers sped, 13 Jun 2011.

  1. Jokers sped

    Jokers sped New Member

    Joined:
    5 Feb 2011
    Messages:
    13
    Likes Received:
    0
    Reputations:
    0
    Как проверить на повторение строчек в текстовом документе?
     
  2. Vollkorn

    Vollkorn Member

    Joined:
    6 Nov 2010
    Messages:
    86
    Likes Received:
    15
    Reputations:
    -6
    Эм.. Например можно первую строку добавить в массив строк, а каждую следующую проверять в цикле есть ли такая в массиве, если нет -- добавляешь в массив, если есть -- берешь следующую строку на проверку, и так далее
     
  3. оlbaneс

    оlbaneс Moderator

    Joined:
    5 Nov 2007
    Messages:
    1,376
    Likes Received:
    1,094
    Reputations:
    356
    http://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D0%BF%D1%83%D0%B7%D1%8B%D1%80%D1%8C%D0%BA%D0%BE%D0%BC

    парсер пробел вставляет. вобщем первая ссылка в гугле - сортировка пузырьком
     
    _________________________
  4. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    тебе только проверить, или еще и удалить дубликаты?
     
  5. AnGeI

    AnGeI Elder - Старейшина

    Joined:
    8 Dec 2008
    Messages:
    395
    Likes Received:
    79
    Reputations:
    16
    PHP:
    $str=file('olbanec.txt');
    foreach (
    $str as $k => $v)
    {
    $str[$k]='';
    if(
    in_array($v,$str)) { $k+=1$out[]="строка № $k повторяется в файле.";}
    else {
    $out_arr[]="строка № $k не повторяется в файле.";}
    }
    file_put_contents('result.txt',join('\r\n',$out_arr));
    $out_ar r замени на $out_arr и будет работать.
     
  6. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    скормил твоему скрипту файл
    получил результат
    к стати пришлось добавить вывод из $out
     
  7. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    вот написал программку, надеюсь, это то, что надо.

    Code:
    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <string>
    #include <algorithm>
    
    int main( int argc, char *argv[] ) {
    	std::ifstream input;
    	std::ofstream output;
    	std::string pathToInputFile;
    	std::string pathToOutputFile;
    	std::string temp;
    	std::vector < std::string > strings;
    
    	std::cout << "Enter a path to input file:";
    	std::cin >> pathToInputFile;
    
    	std::cout << "Enter a path to output file:";
    	std::cin >> pathToOutputFile;
    
    	input.open( pathToInputFile, std::ios::in );
    	output.open( pathToOutputFile, std::ios::out );
    
    	if( !input || !output ) {
    		std::cerr << "Can't open file " << pathToInputFile << " or " << pathToOutputFile << "!\n";
    		return 1;
    	}
    
    	while( !input.eof() ) {
    		std::getline( input, temp );
    		strings.push_back( temp );
    	}
    
    	std::sort( strings.begin(), strings.end() );
    
    	for( size_t i = 0; i < strings.size(); i++ ) {
    		if( std::count( strings.begin(), strings.end(), strings.at( i ) ) > 1 ) {
    			output << "String \"" << strings.at( i ) << "\" is repeated " 
    				<< std::count( strings.begin(), strings.end(), strings.at( i ) ) << " times\n";
    
    			strings.erase( std::remove( strings.begin(), strings.end(), strings.at( i ) ), strings.end() );
    		}
    	}
    
    	return 0;
    }
    
    input:
    Code:
    aaa
    dwpn
    zmte
    umvh
    bslc
    xoyu
    ynut
    silo
    dufp
    kagv
    yofx
    zhaf
    tpum
    mhxa
    aojx
    ygtb
    lfkw
    cgiv
    hndi
    tdxf
    zxyn
    mbwd
    vuey
    gpaf
    fkox
    mnfc
    cgut
    ebzc
    pnus
    vzws
    pngx
    lzhm
    fgyp
    reyk
    ngum
    hxnt
    gscu
    cawr
    jmdu
    crbn
    ghrw
    gpaf
    aqsb
    tefb
    kicg
    ngum
    hxnt
    gscu
    cawr
    jmdu
    gjzs
    hwkv
    mcsx
    dyxj
    lhzo
    lbri
    raos
    ocfw
    rgsf
    hfdv
    qcbj
    bwsz
    tdch
    vuoh
    jymn
    toke
    mqzl
    cfvq
    fpis
    zrcp
    afkg
    vrpb
    abgn
    ezio
    sqdo
    qwcd
    mcvl
    iyvd
    ftyj
    rylq
    zcvb
    nvfm
    iprz
    cijw
    sahb
    alyz
    otus
    mryw
    ktnj
    cqjm
    tjub
    vzhi
    jfup
    byml
    tpjd
    klgt
    tgkp
    aijx
    vzfb
    tlzg
    ieuv
    oafm
    jcnk
    cfap
    wmfx
    wnea
    gmzf
    ecpu
    ghdw
    prbu
    nomk
    mebf
    hvmg
    irzh
    xapr
    pxha
    tnvm
    pncz
    tkah
    kapg
    nvfp
    ejaq
    lhsm
    chiw
    oadw
    fszl
    zodn
    eadj
    vhpy
    ipmy
    ezpv
    fiod
    iqfb
    jmqo
    bgmu
    mjar
    lezb
    fsnh
    dlvi
    yzdj
    zxin
    tyim
    hcqu
    dloc
    rsbv
    ylpi
    upyi
    cxhy
    alyp
    vxji
    ztkj
    zdcv
    exty
    xnjo
    mqrg
    fibl
    defu
    qdgc
    gumo
    hnvs
    xlwi
    qmby
    asop
    lvea
    vwlo
    kqfu
    zdxg
    fown
    qfyj
    ...и так 10078 строк
    
    output:
    Code:
    String "aqer" is repeated 2 times
    String "aqmb" is repeated 2 times
    String "ardo" is repeated 2 times
    String "artj" is repeated 2 times
    String "awtl" is repeated 2 times
    String "bayt" is repeated 2 times
    String "bmtj" is repeated 2 times
    String "bosr" is repeated 2 times
    String "brqi" is repeated 7 times
    String "brxg" is repeated 2 times
    String "btkf" is repeated 2 times
    String "byzl" is repeated 2 times
    String "bzco" is repeated 6 times
    String "cawr" is repeated 2 times
    String "chka" is repeated 2 times
    String "ckvs" is repeated 2 times
    String "cuit" is repeated 2 times
    String "cuyk" is repeated 2 times
    String "cywx" is repeated 2 times
    String "dilw" is repeated 2 times
    String "djom" is repeated 2 times
    String "dyzt" is repeated 2 times
    String "ehnf" is repeated 2 times
    String "evms" is repeated 2 times
    String "eysb" is repeated 2 times
    String "fbwr" is repeated 2 times
    String "fcva" is repeated 6 times
    String "feah" is repeated 2 times
    String "fehj" is repeated 2 times
    String "fmcu" is repeated 2 times
    String "fnyq" is repeated 2 times
    String "fobx" is repeated 2 times
    String "fqbz" is repeated 2 times
    String "ftyj" is repeated 2 times
    String "fwbt" is repeated 4 times
    String "gaye" is repeated 6 times
    String "gpaf" is repeated 2 times
    String "gqha" is repeated 6 times
    String "grnq" is repeated 2 times
    String "gscu" is repeated 2 times
    String "gyvs" is repeated 2 times
    String "hidv" is repeated 2 times
    String "hnaq" is repeated 2 times
    String "hnpx" is repeated 2 times
    String "hoxz" is repeated 2 times
    String "hprk" is repeated 2 times
    String "hqml" is repeated 2 times
    String "hrpa" is repeated 2 times
    String "hsia" is repeated 2 times
    String "hvix" is repeated 2 times
    String "hwkg" is repeated 2 times
    String "hxnt" is repeated 2 times
    String "igtw" is repeated 2 times
    String "ilgz" is repeated 2 times
    String "ingt" is repeated 2 times
    String "injt" is repeated 2 times
    String "iotb" is repeated 2 times
    String "jexk" is repeated 2 times
    String "jkzu" is repeated 6 times
    String "jmdu" is repeated 2 times
    String "jtvh" is repeated 6 times
    String "juxm" is repeated 2 times
    String "kauf" is repeated 2 times
    String "kcrn" is repeated 2 times
    String "kgpu" is repeated 2 times
    String "kmgx" is repeated 6 times
    String "kprl" is repeated 2 times
    String "kzts" is repeated 2 times
    String "lefy" is repeated 2 times
    String "lemw" is repeated 2 times
    String "mcrx" is repeated 2 times
    String "miux" is repeated 2 times
    String "mixg" is repeated 2 times
    String "mwyb" is repeated 2 times
    String "mxji" is repeated 2 times
    String "mytb" is repeated 2 times
    String "ngum" is repeated 2 times
    String "nkmz" is repeated 2 times
    String "nlzk" is repeated 2 times
    String "npfg" is repeated 2 times
    String "npjy" is repeated 2 times
    String "nqjw" is repeated 2 times
    String "ntbz" is repeated 2 times
    String "ntrh" is repeated 2 times
    String "nxlj" is repeated 7 times
    String "nxvw" is repeated 2 times
    String "nyst" is repeated 2 times
    String "oafm" is repeated 2 times
    String "oirs" is repeated 2 times
    String "ojpi" is repeated 2 times
    String "olyj" is repeated 2 times
    String "oqgn" is repeated 2 times
    String "osif" is repeated 2 times
    String "oslh" is repeated 2 times
    String "otqy" is repeated 2 times
    String "ower" is repeated 2 times
    String "oxuw" is repeated 2 times
    String "pdxv" is repeated 2 times
    String "pgmz" is repeated 2 times
    String "pomt" is repeated 2 times
    String "prtk" is repeated 2 times
    String "pukq" is repeated 2 times
    String "qbac" is repeated 2 times
    String "qfpv" is repeated 2 times
    String "qhwg" is repeated 2 times
    String "qihl" is repeated 2 times
    String "qjai" is repeated 2 times
    String "qlok" is repeated 2 times
    String "qpbd" is repeated 2 times
    String "qubf" is repeated 2 times
    String "rafc" is repeated 2 times
    String "rfkq" is repeated 2 times
    String "rgjf" is repeated 2 times
    String "rolg" is repeated 6 times
    String "rvfm" is repeated 2 times
    String "rxpg" is repeated 2 times
    String "sadl" is repeated 2 times
    String "silo" is repeated 2 times
    String "spqg" is repeated 7 times
    String "sqcg" is repeated 2 times
    String "stvy" is repeated 2 times
    String "sxuk" is repeated 2 times
    String "tjma" is repeated 3 times
    String "trev" is repeated 2 times
    String "tuvw" is repeated 2 times
    String "txpz" is repeated 2 times
    String "uakt" is repeated 2 times
    String "ueak" is repeated 2 times
    String "uopq" is repeated 2 times
    String "vkcn" is repeated 2 times
    String "vpgk" is repeated 2 times
    String "vqeo" is repeated 2 times
    String "vrqu" is repeated 2 times
    String "vubq" is repeated 2 times
    String "vxbq" is repeated 2 times
    String "vxzk" is repeated 2 times
    String "vymu" is repeated 2 times
    String "wadj" is repeated 2 times
    String "wcor" is repeated 2 times
    String "wjoc" is repeated 2 times
    String "wqxe" is repeated 2 times
    String "wtnk" is repeated 2 times
    String "wzax" is repeated 2 times
    String "xaye" is repeated 2 times
    String "xhmo" is repeated 2 times
    String "xirq" is repeated 2 times
    String "xlph" is repeated 2 times
    String "xroc" is repeated 2 times
    String "xvpj" is repeated 2 times
    String "xyak" is repeated 2 times
    String "xzsf" is repeated 2 times
    String "yaux" is repeated 2 times
    String "yctq" is repeated 2 times
    String "ycwi" is repeated 6 times
    String "yhuz" is repeated 2 times
    String "ykco" is repeated 2 times
    String "ynez" is repeated 2 times
    String "ypbo" is repeated 2 times
    String "yqfn" is repeated 2 times
    String "yskg" is repeated 2 times
    String "zatn" is repeated 6 times
    String "zjof" is repeated 2 times
    String "zlac" is repeated 2 times
    String "zodi" is repeated 2 times
    String "zrdy" is repeated 2 times
    String "zxwd" is repeated 2 times
    String "zyuf" is repeated 2 times
    
    

    бинарь:
    http://dl.dropbox.com/u/29025286/Different_sucks/programm2.exe

    UPD: ну что, поддержим традицию "Запости кодес на всех известных ЯП"?)
     
    #7 Ins3t, 13 Jun 2011
    Last edited: 13 Jun 2011
  8. Jokers sped

    Jokers sped New Member

    Joined:
    5 Feb 2011
    Messages:
    13
    Likes Received:
    0
    Reputations:
    0
    У меня есть текстовик, в нем допустим 10к аков, и мне нужно его проверить на дубликаты
     
  9. twost

    twost Member

    Joined:
    24 Apr 2010
    Messages:
    4
    Likes Received:
    5
    Reputations:
    5
    FAIL
    Code:
    perl -ne "$b{$_}++ || print" input.txt > output.txt
     
    #9 twost, 13 Jun 2011
    Last edited: 13 Jun 2011
  10. AlexTheC0d3r

    AlexTheC0d3r Elder - Старейшина

    Joined:
    25 Jul 2008
    Messages:
    388
    Likes Received:
    179
    Reputations:
    18
    прочитайте название темы и посмотрите как НЕ НАДО называть тему.
     
  11. |qbz|

    |qbz| Banned

    Joined:
    25 Dec 2009
    Messages:
    385
    Likes Received:
    169
    Reputations:
    65
    PHP:
    <?php
        
    function countStrings($a)
        {
            
    $r = array();
            foreach (
    $a as $v)
            {
                if (
    $r[$v] == ''){$r[$v] = 1;}else{$r[$v] += 1;}
            }
            foreach(
    $r as $k => $v)
            {
                if (
    $v 1)
                {
                    echo(
    $k ' povtoryalos ' $v ' raz.<br>');
                }
            }
        }
        
        
    countStrings(file('./akki.txt'));
    ?>
     
    #11 |qbz|, 13 Jun 2011
    Last edited: 14 Jun 2011
  12. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    обновил пост, в файл запишутся дубликаты и их количество.
     
  13. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    точку перед raz пропустили.

    p.s:и кто вас учил код в 1 строку писать?
    ппц))
     
  14. |qbz|

    |qbz| Banned

    Joined:
    25 Dec 2009
    Messages:
    385
    Likes Received:
    169
    Reputations:
    65
    я хочу, чтобы никто непонил :Д
     
  15. dpe_x

    dpe_x Elder - Старейшина

    Joined:
    8 Sep 2010
    Messages:
    155
    Likes Received:
    35
    Reputations:
    14
    это типо, чтобы как самый короткий казался
     
  16. aka dexter

    aka dexter Elder - Старейшина

    Joined:
    23 Jun 2006
    Messages:
    539
    Likes Received:
    801
    Reputations:
    74
    raptor2, и в бой...
     
  17. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    что за раптор?
     
  18. Indigo_O

    Indigo_O New Member

    Joined:
    14 Apr 2011
    Messages:
    1
    Likes Received:
    1
    Reputations:
    0
    ёмане.. прог то в тырнетах подобных КУЧА. поищи на ачате прогу от inoy. удалятор (udalyator) называется. незаменимая вещь в подобных делах.
     
  19. M_script

    M_script Members of Antichat

    Joined:
    4 Nov 2004
    Messages:
    2,581
    Likes Received:
    1,317
    Reputations:
    1,557
    sl.Sorted := true; sl.Duplicates := dupIgnore;
    sl.LoadFromFile('input.txt'); sl.SaveToFile("output.txt");
     
  20. Evgeniy

    Evgeniy Member

    Joined:
    25 Feb 2011
    Messages:
    0
    Likes Received:
    8
    Reputations:
    0
    Вот--->
    Самая удобная на мой взгляд.
     
Loading...