Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 906
- #include <iostream>
- #include <cstring>
- using namespace std;
- void count(char *word)
- {
- int count = 0;
- int tempcount = 0;
- int term = 0;
- int sterm = 0;
- int eterm = 0;
- bool flag1 = true;
- bool flag2 = true;
- for (int i = 0;i < strlen(word);i++)
- {
- if (word[i] == '0' || word[i] == '1' || word[i] == '2' || word[i] == '3' || word[i] == '4' || word[i] == '5' || word[i] == '6' || word[i] == '7' || word[i] == '8' || word[i] == '9')
- {
- count++;
- if (flag1 == true)
- {
- term = i;
- flag1 = false;
- }
- flag2 = true;
- }
- else
- {
- count = 0;
- if (flag2 == true)
- {
- flag2 = false;
- }
- flag1 = true;
- }
- if (count > tempcount)
- {
- tempcount = count;
- sterm = term;
- eterm = i;
- }
- }
- char ptr[1000] = { '\0' };
- for (int i = sterm, j = 0;i <= eterm;i++, j++)
- {
- ptr[j] = word[i];
- }
- int len = strlen(ptr);
- int ost = len % 3;
- for (int i = 0; i<ost; i++)
- cout << ptr[i];
- for (int i = ost; i<len; i += 3)
- {
- if (ost != 0)
- cout << " " << ptr[i] << ptr[i + 1] << ptr[i + 2];
- else
- cout << ptr[i] << ptr[i + 1] << ptr[i + 2] << " ";
- }
- cout << endl;
- }
- int main()
- {
- char word[1001] = { '\0' };
- cin.getline(word, 1000);
- count(word);
- return 0;
- }
- 912
- #include <iostream>
- #include <cstring>
- #include <iomanip>
- #include <cctype>
- #define DELIMS " ,.!?-0123456789\n"
- using namespace std;
- void avg(char *str)
- {
- double sum = 0;
- double count = 0;
- char *token = strtok(str, DELIMS);
- while (token != 0)
- {
- ++count;
- sum += strlen(token);
- token = strtok(0, DELIMS);
- }
- if (count == 0)
- {
- cout << "0.0";
- }
- else
- {
- cout << fixed << setprecision(9) << sum / count << endl;
- }
- }
- bool isreal(char x[]);
- int main()
- {
- char text[50];
- cin.getline(text, 50, '#');
- bool isreal = false;
- for (int i = 0; i<strlen(text); i++)
- {
- if(!(isalnum(text[i]) || text[i] == '?' || text[i] == ',' || text[i] == '.' || text[i] == '!' || text[i] == '-' || text[i] == ' '))
- {
- isreal = true;
- }
- }
- if (isreal == false)
- {
- avg(text);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement