//в заданной строке поменять местами первый и последний символ
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cout << "String:\n";
getline(cin, s);
swap(s[0],s[s.size()-1]);
cout <<s<<"\n";
system("pause");
return 0;
}
//в заданой строке посчитать кол-во слов
#include <iostream>
using namespace std;
int main()
{
char s[80];
int word, count = 0;
cout << "Введите несколько слов: " << endl;
cin.get(s, 80);
int i = 0;
while (s[i] == ' ' && s[i] != '\0')
i++;
word = 0;
while (s[i] != '\0') {
if (s[i] != ' ' && word == 0)
{
word = 1;
count++;
}
else if (s[i] == ' ')
word = 0;
i++;
}
cout << "Количество слов в строке: " << count;
cin.get(); cin.get();
return 0;
}
//в заданой строке поменять первое и последнее слова местами
#include<stdio.h>
#include<math.h>
#include<string.h>
#define N 50
int main()
{
char str1[N];
char str2[N];
char str3[N];
int i1=0,i2,l,k1=0,k2=0,k3;
printf("Введите строку: \n");
gets(str1);
strcpy(str2,str1);
l = strlen(str1);
i2=l-1;
for (i1,i2;i1<=l-1;i1++,i2--)
{
str2[i1]=str1[i2];
}
i1=0;i2=l-1;
strcpy(str3,str2);
for (i1;i1<=N;i1++)
{
k2=i1;
k3=i1;
if (str2[i1]==' ')
{
for (k1,k2;k1<=k3;k2--,k1++)
{
str3[k1]=str2[k2];
}
k1=k3;
k2=k3;
}
}
printf("Первоначальная строка: %s\n",str1);
printf("Преобразованная: %s\n",str2);
printf("Преобразованная: %s\n",str3);
system("pause");
}