Quipex

zadanie_6

Nov 3rd, 2015
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. // zadanie_6.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <clocale>
  6. #include <iostream>
  7. #include <string>
  8. using namespace std;
  9.  
  10. int kolvo(char a, bool sl)
  11. {
  12.     int m=0;
  13.     if((sl)&&(a=='5'))
  14.     {
  15.         m=1;
  16.     }
  17.     return m;
  18. }
  19.  
  20. int main()
  21. {
  22.     setlocale(0, "rus");
  23.     char st[100];
  24.     gets(st);
  25.     int i,n=0,k=0;
  26.     bool slovo=false;
  27.     if (st[0]!=' ')
  28.         slovo=true;
  29.  
  30.     cout<<"Число - кол-во цифр 5\n";
  31.  
  32.     for(i=0;i<strlen(st);i++)
  33.     {
  34.         if((st[i-1]==' ')&&(st[i]!=' '))
  35.         {
  36.             slovo=true;
  37.         }
  38.         else
  39.             if((st[i]==' ')&&(st[i-1]!=' '))
  40.             {
  41.                 slovo=false;
  42.                 n=0;
  43.             }
  44.         n+=kolvo(st[i],slovo);
  45.         k=n;
  46.         if(slovo)
  47.             cout<<st[i];
  48.         if((slovo)&&((st[i+1]==' ')||((i+1)==strlen(st))))
  49.             cout<<" - "<<k<<endl;
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment