Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- using namespace std;
- //podgotovka za kontrolno
- bool isLetter(char c) {
- return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
- }
- bool isUpper(char c) {
- return ((c >= 'A' && c <= 'Z'));
- }
- bool isLower(char c) {
- return (c >= 'a' && c <= 'z');
- }
- int capital(char* str) {
- for (size_t i = 0; str[i] != '\0'; i++)
- {
- if (i == 0 && isLower(str[i])) {
- str[i] = str[i] ^ ' ';
- }
- if (i != 0 && !isLetter(str[i - 1]) && isLower(str[i])) {
- str[i] = str[i] ^ ' ';
- }
- else {
- if (isUpper(str[i]) && i != 0 && isLetter(str[i - 1])) {
- str[i] = str[i] ^ ' ';
- }
- }
- }
- return 0;
- }
- void longestWord(char * txt) {
- unsigned start = 0, max_start = 0;
- unsigned Cnt = 0, max_cnt = 0;
- for (size_t i = 0; txt[i] != '\0'; i++)
- {
- if (i == 0 && isLetter(txt[i])) {
- start = i;
- }
- if (i != 0 && !isLetter(txt[i - 1]) && isLetter(txt[i])) {
- start = i;
- }
- if (!isLetter(txt[i])) {
- Cnt = 0;
- }
- else {
- Cnt++;
- }
- if (max_cnt < Cnt) {
- max_cnt = Cnt;
- max_start = start;
- }
- }
- for (size_t i = max_start; i < max_cnt + max_start; i++)
- {
- cout << txt[i];
- }
- cout << endl;
- }
- int main()
- {
- char str[] = "-this is a tExt.for CAPitalize... hahahahha";
- capital(str);
- cout << str << endl;
- cout << "The longest word is:";
- cout << endl;
- longestWord(str);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement