13.04.2011, 19:13. Просмотров 428. Ответов 0
Задание такое: Выдать на экран слово, соответствующее номеру, введенному с клавиатуры.
Посчитать слова я смог, а вот как дальше....
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| #include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream>
#include <locale.h>
using namespace std;
int _tmain()
{ setlocale(LC_ALL,"rus");
char s[255];
cout<<"Введите строку: ";
gets(s);
int a,b,i;
a=0;
b=0;
for (i=0;i<strlen(s)-1;i++)
if ((s[i]==' ') && (s[i+1]!=' '))
a=a+1;
if (s[0]!=' ')
a=a+1;
cout<<"В веденной строке слов: "<<a<<endl;
_getch();
return 0;
} |
|