Results 1 to 7 of 7

Thread: C++ ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Decrux's Avatar
    Join Date: Aug:2016
    Location: .
    Posts: 562

    C++ ?

    ,
    -
    ( 50 ) . ( 50 ).
    , 1 space, .
    count + 1 1 0.
    :

    Code:
    PHP Code:
    // funkcii.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; char arr[50]; void enterData() {     cout << "Enter a sentence not bigger than [50] symbols, and I will count the words: " << endl;     cin.getline(arr50); } void countWords() {     int count 0;     char prevchar;     for (int i 0strlen(arr); i++) {         if (arr[i] == ' ') {             count++;         }     }     cout << "There are " << count << " words!" << endl; } int main() {     enterData();     countWords();     return 0; } 
    , space. .
    Last edited by Decrux; 8th March 2017 at 19:13.

  2. #2
    Registered User
    Join Date: Mar:2014
    Location:
    Posts: 16
    Code:
    void countWords()
    {
    	int count = 0;
    
        char szPrevChar = '\0';
    	
    	const char szSpaceDelimeter = ' ';
    	
        for (int i = 0; i < strlen(arr); i++)
       {
            if ( arr[i] == szSpaceDelimeter  && szPrevChar != szSpaceDelimeter )
                count++;
            
    		
    		szPrevChar = arr[i];
        }
    
    	if( count == 0 && strlen(arr) > 0 )
    		count++;
    
        cout << "There are " << count << " words!" << endl;
    }
    .
    Last edited by Borrowyou; 8th March 2017 at 19:47.

  3. #3
    Registered User ined's Avatar
    Join Date: Nov:2006
    Location: Varna
    Posts: 1,078
    Code:
    #include <iostream>
    
    using namespace std;
    
    char arr[50];
    
    void enterData() 
    {
        cout << "Enter a sentence not bigger than [50] symbols, and I will count the words: " << endl;
        cin.getline(arr, 50);
    }
    
    void countWords() 
    {
        int count = 0;
        int flag = 1;
        
        for (int i = 0; i < strlen(arr); i++) 
        {
            if (flag && arr[i]!=' ') 
            {
                count++; 
                flag=0;
            }
            if (arr[i] == ' ') flag=1;
        }
        cout << "There are " << count << " words!" << endl;
    }
    
    int main()
    {
        enterData();
        countWords();
        return 0;
    }
    ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
    Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173

  4. #4
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    , ?
    , :
    " ? "
    :
    " , ? "
    Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19

  5. #5
    Registered User Decrux's Avatar
    Join Date: Aug:2016
    Location: .
    Posts: 562
    . ined, if. ?
    Last edited by Decrux; 9th March 2017 at 14:35.

  6. #6
    Registered User ined's Avatar
    Join Date: Nov:2006
    Location: Varna
    Posts: 1,078
    Code:
    void countWords() 
    {
        int count = 0;
        int flag = 1;
        
        for (int i = 0; i < strlen(arr); i++) 
        {
            if (flag && arr[i]!=' ') count++; 
            flag = arr[i] == ' ';
        }
        cout << "There are " << count << " words!" << endl;
    }
    if
    Last edited by ined; 9th March 2017 at 15:34.
    ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
    Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173

  7. #7
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    if , - , - flag, .

    , - a z A Z, 0-9, ( ). , , .

    - if-a , , , . . , .

    , ined, - .

    , .
    Last edited by 4eRNoBiL; 9th March 2017 at 16:30.
    Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |