Results 1 to 7 of 7
Thread: C++ ?
Hybrid View
-
8th March 2017 19:13 #1
C++ ?
,
-
( 50 ) . ( 50 ).
, 1 space, .
count + 1 1 0.
:
, space. .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(arr, 50); } void countWords() { int count = 0; char prevchar; for (int i = 0; i < strlen(arr); i++) { if (arr[i] == ' ') { count++; } } cout << "There are " << count + 1 << " words!" << endl; } int main() { enterData(); countWords(); return 0; }Last edited by Decrux; 8th March 2017 at 19:13.
-
8th March 2017 19:46 #2Registered 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.
-
8th March 2017 19:49 #3Code:
#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
-
9th March 2017 10:44 #4
, ?
, :
:" ? "
" , ? "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
-
9th March 2017 14:26 #5
. ined, if. ?
Last edited by Decrux; 9th March 2017 at 14:35.
-
9th March 2017 15:25 #6ifCode:
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; }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
-
9th March 2017 16:28 #7
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




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in