Search

'단어'에 해당되는 글 1건

  1. 2013.01.26 CPP 토큰으로 단어 구분후 단어별 카운트 프로그램
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>

#include <string>

using namespace std;

 

int main()

{

    string str;

    string tempStr[10];

    int tempStrSeq = 0;

    int tempStrCount[10] = {0};

    int start = 0, many = 0;

    getline(cin, str, '\n');

    for( int i = 0 ; i < str.length() ; i++ )

    {

        if( str.at(i) == ' ' || str.at(i) == ',' || str.at(i) == '.' )

        {

            if( many != 0)

            {

                cout << str.substr(start,many) << endl;

                int flag = 0;

                for( int j = 0 ; j < tempStrSeq + 1 ; j++ )

                {

                    if( tempStr[j].compare(str.substr(start,many)) == 0 )

                    {

                        flag++;

                        tempStrCount[j]++;

                    }

                    else

                    {

                        // 같지않다면

                    }

                }

                if( flag == 0)

                {

                    tempStr[tempStrSeq] = str.substr(start,many);

                    tempStrCount[tempStrSeq]++;

                    tempStrSeq++;

                }

                cout << "s : "<< start << "m : " << many << endl;

                many = 0;

            }

            start = i+1;

        }

        else

        {

            many++;

        }

    }

    if( many != 0)

    {

        cout << str.substr(start,many) << endl;

        int flag = 0;

        for( int j = 0 ; j < tempStrSeq + 1 ; j++ )

        {

           if( tempStr[j].compare(str.substr(start,many)) == 0 )

            {

                flag++;

                tempStrCount[j]++;

            }

            else

            {

                // 같지않다면

            }

        }

        if( flag == 0)

        {

            tempStr[tempStrSeq] = str.substr(start,many);

            tempStrSeq++;

            tempStrCount[tempStrSeq]++;

        }

        cout << "s : "<< start << "m : " << many << endl;

    }

 

    // TODO: 계산

 

    for( int i = 0 ; i < 10 ; i++ )

    {

        cout << tempStr[i] ;

        cout << " " << tempStrCount[i] << endl;

    }

}

'Programming > C,CPP,CS' 카테고리의 다른 글

아스키코드표  (0) 2013.05.02
프로그래밍용으로 좋은 폰트  (0) 2013.03.23
CPP string 줄단위 입력  (0) 2013.01.26
링크드리스트 학생관리  (0) 2013.01.19
C언어 달력소스코드  (0) 2013.01.13