hannx91 utworzono 5 lutego 2011 utworzono 5 lutego 2011 witam choruje trochę i jestem jakoś rozkojarzony, nie mogę się skupić. Chce napisać program który ma plik in.txt w którym są po kolei ułożone adresy stron i i ich podstron. [code]http://18uthome.com/?tag=challenge http://18uthome.com/?tag=hennessey http://18uthome.com/?tag=bowerboat http://18uthome.com/?tag=challenger http://18uthome.com/?tag=qualifying http://18uthome.com/?tag=drag-korea http://18uthome.com/?tag=motorcycle http://18uthome.com/?tag=international http://18uthome.com/?tag=www-watercar-com http://haha12333.18uthome.com/web/z039.htm http://www.101news.eu/page/15/ http://www.101news.eu/our-aim/ http://www.101news.eu/tag/mozilla/ http://www.101news.eu/category/health/page/3/ http://www.101news.eu/category/technology/page/5/ http://www.101news.eu/category/headline/page/16/ http://www.101news.eu/category/news/page/3/ http://www.101news.eu/2010/12/climate-change-talks-deadlocked/ http://www.101news.eu/2010/12/president-obamas-vacation-home/ http://www.101news.eu/2010/12/snow-sparks-confusion-across-europe/ http://www.101news.eu/2010/12/15-killed-in-pak-crowded-market/ http://www.101news.eu/2010/12/wikileaks-julian-assanges-account-being-closed/ http://www.101news.eu/2010/11/diabeties-cant-b-controlled-alone-by-medicine/ http://www.101news.eu/2010/12/chinese-premier-in-pakistan-for-rare-visit/ http://www.101news.eu/2010/12/sony-buys-ps3-chip-plant-back-off-toshiba/ http://www.101news.eu/2010/12/google-mobile-head-declare-nexus-one-too-determined/ http://www.101news.eu/2010/11/tony-parker-knew-about-his-split-with-eva/ http://www.101news.eu/2010/11/psychology-of-yes-by-lori-turner/comment-page-2/ http://www.101news.eu/2010/11/lady-gaga-justin-top-awards-at-mtv/comment-page-1/ http://www.101news.eu/2010/10/shrine-of-abdullah-shah-ghazi-will-be-open-by-tomorrow/ http://www.101news.eu/2010/11/lady-gaga-justin-top-awards-at-mtv/comment-page-2/ http://www.101news.eu/2010/10/early-next-year-toshiba-tablet-will-appear-in-the-u-s-and-japan/ http://www.101news.eu/2010/11/what-next-on-apple%E2%80%99s-mind-version-iphone-and-ios-4-2-release/comment-page-2/ http://www.101news.eu/2010/11/australia-customer-self-reliance-declines-5-3-on-central-bank-rate-raise/comment-page-2/ http://174.132.114.66/~crsite/ http://174.132.114.66/~crsite/index.php?action=page_display&PageID=26 http://174.132.114.66/~crsite/index.php?action=page_display&PageID=12[/code] i do pliku out.txt daje po jednym adresie z każdej domeny (losowym). Wiem, ze to proste, ale jakoś nie mogę się skupić, katar nie daje.. napisałem coś takiego, ale podczas uruchomienia mam błąd. [code]#include<iostream> #include<fstream> #include <stdlib.h> using namespace std; int main(void){ int i,j,tmp,k,l; j=1; char tablica[200]; char sub[100][200]; ifstream odczyt("in.txt"); ofstream zapis("out.txt"); while(odczyt >> tablica){ tmp=0; for(i=0;i<=15;i++){ tmp=i+tmp; if (tablica[i]!=sub[j][i]) { l=rand()%j; zapis << sub[l] << endl; i=i+15; j=0; }//if if (tmp==120) { for(k=0;k<=200;k++){ sub[j-1][k]=tablica[k]; } j++; }//if }//for }//while system("PAUSE"); return 0; }//main [/code] mogłby ktoś to poprawic?
wojtex5 komentarz 5 lutego 2011 komentarz 5 lutego 2011 napisałem program od zera... i chyba działa poprawnie (tak na 98%) [code]#include <iostream> #include <fstream> #include <vector> #include <string> #include <cstdlib> #include <ctime> void losuj_i_pisz(std::vector<std::string> &wektor,std::ofstream&F) { std::string tmp=wektor[rand()%wektor.size()]; F<<tmp<<"\n"; } int main() { srand(time(0)); std::string tmp1,tmp2; std::cout<<"podaj nazwe pliku wejsciowego:\t"; std::cin>>tmp1; std::cout<<"podaj nazwe pliku wyjsciowego:\t"; std::cin>>tmp2; std::ifstream plik(tmp1.c_str()); std::ofstream wyjscie(tmp2.c_str()); std::string tmp,ostatni; std::vector<std::string> adresy; getline(plik,tmp); adresy.push_back(tmp); ostatni=tmp.substr(0,14); while(getline(plik,tmp)) { if(ostatni!=tmp.substr(0,14)) { losuj_i_pisz(adresy, wyjscie); adresy.clear(); } ostatni=tmp.substr(0,14); adresy.push_back(tmp); } losuj_i_pisz(adresy,wyjscie); std::cout<<"koniec!\n"; system("pause"); } [/code] u mnie działa poprawnie. 1
Wciąż szukasz rozwiązania problemu? Napisz teraz na forum!
Możesz zadać pytanie bez konieczności rejestracji - wystarczy, że wypełnisz formularz.