Results 1 to 6 of 6

Thread: Need Help C++

  1. #1

    Default Need Help C++


    Hello mga master.. naa koy program ba.. di ni sya sa skwelahan nag praktis2 ra ko.. moread ni siya ug input sa text file din iya e determine pila kabuok ang duplicate na words.. say ang naa sa text file kay "the quick brown fox the quick the the hello wolrd" ang output niya sa console kay 2 kay ang ang "the" ug "quick" ra man ang na duplicate. Di mo matter kon kapila nagbalik2 na word.. basta naa na siyay kapareha 1 ra jud ang ihap.. ako gibuhat ani kay gisulod nako siya sa vector.. ganahan ta ko ug mas efficient na algo ba mao mangayo ko ug tabang.. hehe.. dara akong code

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <vector>
    
    
    using namespace std;
    
    
    
    
    int main()
    {
        vector <string> words;
        vector <string> duplicate;
        string str;
        ifstream file("input.txt");
        while(file >> str)
        {
            words.push_back(str);
        }
        int n = 0;
        for(int i = 1; i < words.size(); i++)
        {
            for(int j = 0; j < i; j++)
            {
                if(words[j] == words[i])
                    {
                        if(duplicate.size() > 1)
                        {
                            for(int k = 0; k < duplicate.size(); k++)
                            {
                                for(int m = 0; m < k; m++)
                                {
                                    if(duplicate[m] == duplicate[k])
                                    {
                                        duplicate.erase(duplicate.begin()+k);
                                    }
                                }
    
    
                            }
                        }
                        else
                            duplicate.push_back(words[i]);
    
    
                    }
                n++;
            }
    
    
        }
        for(int i = 0; i < duplicate.size(); i++)
        {
            cout<< i+1 <<".) " << duplicate[i]<<endl;
        }
        cout << "Total Words = " << words.size() << "\tDuplicate = " << duplicate.size() <<'\t'
            << "n = " << n;
    
    
    
    
        return 0;
    }
    btw, unsa nindot na IDE para C++? codeblocks ako gamit ron pero nakabasa man gud ko buggy daw ang codeblocks sa windows..


    Thanks
    Last edited by NapoleonBlownapart; 07-10-2014 at 02:04 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2009
    Gender
    Male
    Posts
    478
    Gubota ani na code.

    Code:
    if(duplicate.size() > 1)
                        {
                            for(int k = 0; k < duplicate.size(); k++)
                            {
                                for(int m = 0; m < k; m++)
                                {
                                    if(duplicate[m] == duplicate[k])
                                    {
                                        duplicate.erase(duplicate.begin()+k);
                                    }
                                }
    
    
                            }
                        }
                        else
                            duplicate.push_back(words[i]);
    Pwede na nimo gamitan ug std::set?

  3. #3
    Quote Originally Posted by kamsky View Post
    Gubota ani na code.
    hahaha.. mao lage boss gabie na kaayo gud.. ako giusab ang code karon buntag
    Code:
    vector <string> duplicate;
    bool notListed(string);
    int main()
    {
        vector <string> words;
        
        string str;
        ifstream file("input.txt");
        while (file >> str)
        {
            words.push_back(str);
        }
        int n = 0;  
        for (size_t i = 1; i < words.size(); i++)
        {
            for (size_t j = 0; j < i; j++)
            {
                n++;
                if (words[i] == words[j]){
                    if (notListed(words[i])){
                        
                        duplicate.push_back(words[i]);
                    }    
                }
                else
                    continue;
            }
            
        }
        for (size_t i = 0; i < duplicate.size(); i++)
            cout << duplicate[i] << std::endl;
        cout << "Total Words = " << words.size() << "\tDuplicate = " << duplicate.size() << '\t'
            <<"\tn = " << n << std::endl;
    
    
        return 0;
    }
    
    
    bool notListed(string targetWord){
        for (size_t i = 0; i < duplicate.size(); i++)
        {
            if (targetWord == duplicate[i]){
                return false;
            }
            else
                return true;
        }
    }
    pwede ra man set pero wa pa ko katuon ana gud vector pa man ko ron..hehe
    Last edited by NapoleonBlownapart; 07-10-2014 at 12:50 PM.

  4. #4
    leksyon mani nmu lolz pero wla pa nuon mi naabot dha bro hehehe ....

  5. #5
    unsa man nindot e project para c++?

  6. #6
    Have you solved your problem already with that topic or still not? Please do tell me how it's working with it.... cause I am totally lost, you know there is already like 17th version of C++ and everything may be totally damn in other words anyway for this one.

  7.    Advertisement

Similar Threads

 
  1. PAGIBIG/HDMF Loan problem, need help
    By franz in forum Business, Finance & Economics Discussions
    Replies: 28
    Last Post: 09-21-2016, 10:33 AM
  2. need help!
    By jats_jats2004 in forum Business, Finance & Economics Discussions
    Replies: 5
    Last Post: 04-18-2013, 02:09 PM
  3. need help with p900
    By kloos in forum Gizmos & Gadgets (Old)
    Replies: 8
    Last Post: 09-04-2006, 01:55 PM
  4. excel programs; needs help guys!!!
    By rufo in forum Software & Games (Old)
    Replies: 3
    Last Post: 01-14-2006, 12:18 PM
  5. Need Help: Song & Artist GSM Ad
    By iceman in forum Music & Radio
    Replies: 1
    Last Post: 05-23-2005, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top