.
.
//arb2014_gusen_8_5
#include <iostream.>
using namespace std;
const m=20;
void main()
{
char str[m], k;
int i,j,n;
bool fl = true;
cout << "Enter string:";
cin >> str; // 19 .
// .
// \0 .
for(n=0; str[n]!='\0'; n++);
for(i=0;i<n && fl;i++)
{
fl = false;
for(j=0;j<n-i-1;j++)
if (str[j] > str[j+1])
{
k=str[j];
str[j]= str[j+1];
str[j+1] = k;
fl = true;
}
}
cout << str << endl;
// - ( - \0)
}
7
, ,
.
,
.
() .
29 .
//arb2014_gusen_8_6
#include <iostream>
#include <cstring> // - (\0)
using namespace std;
void main()
{
char buf[30];
int n;
bool fl=true;
cout << "Enter text:";
while(fl)
{ cin >> buf; // .
n = strlen(buf); // - .
if (buf[n-1] == '.')
{ n--;
fl=false;
}
for (int i=n-1; i>=0; i--)
cout << buf[i];
if (fl)
cout << ' ';
}
cout << '\n';
}
8
, ,
. ,
m.
.
.
get()
.
get(f) f.
//arb2014_gusen_8_7
#include <iostream>
using namespace std;
void main()
{
char symb;
int count_word=0,count_let=0;
cout << "Enter text:";
symb=cin.get(); // ( )
while (symb!= '.')
{
if (symb==' ')
{
if (count_let==2) count_word++;
count_let=0;
}
else
if (symb=='m') count_let++;
symb=cin.get(); // . cin.get(symb);
}
if (count_let==2) count_word++;
cout << "Word count = " << count_word << '\n';
}
// :
// while ((symb=cin.get())!= '.')
// symb=cin.get();
9
,
(\n). N,
N &.
getline(buf,size,symb)
, symb ( ).
|
|
size-1 , symb .
symb ( ) \0.
buf.
.
//arb2014_gusen_8_8
#include <iostream>
#include <string>
using namespace std;
void main()
{
const size=100;
char buf[size];
int n,i,lstr;
cout << "Enter text:\n";
while(1)
{
cin.getline(buf, size, '\n');
if (buf[0] == '\0')
break;
lstr=strlen(buf);
if (buf[lstr-1] >= '1' && buf[lstr-1] <= '9') // .
n = buf[lstr-1] - '0';
else
n = 0;
for(i=0; i<n && i<lstr; i++)
buf[i] = '&';
cout << "Result:" << endl << buf <<endl;
cout<< "Enter new line or press 'Enter':"<<endl;
}
}
10
, .
: <Ctrl>z
<Enter>
read(buf, size) buf size ,
.
, gcount() .
//arb2014_gusen_8_9
#include <iostream>
#include <cstring>
using namespace std;
void main()
{
const size=10;
char buf[size];
int n,i,count=0;
cout << "Enter text:"<<endl;
while(!cin.eof())
{
cin.read(buf, size);
n=cin.gcount();
for(i=0; i<n; i++)
if(buf[i]=='\n')
count++;
}
cout << "Number of line =" << count <<'\n';
}
11