Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int str1_len(char* str1);
- int str2_len(char* str2);
- int str3_len(char* str3);
- char* str_cpy(char* str1, char* str2); //скопировать str1 в str2 строку;
- char* str_cat(char* str2,char* str); //записать вторую строку в первую
- int str_cmp(char* str2,char* str); // сравнение строк (вычитать символы 1 из другой
- char* str_str(char* str,char* str2); //поиск строки в строке
- int words_count(char* str1); // подсчет колличества слов
- int ch_str(char* str1, char ch); // кол-во символов в строке
- int sum_of_digits(char* str3); // сумма цифр
- int sum_of_decimal(char* str3); // сумма чисел
- char* reverse_str(char* str); // переворот всего массива
- char* reverse_substr(char* str, int start, int end); // переворот определенного куска массива
- void swap(char* a, char* b);
- int longest_word(char* str2);
- int shorter_word(char* str2);
- void print_words(char* str);
- char* reverse_words(char* str);
- char* s_gets(char* str, int buf_size);
- int main()
- { const int size = 50;
- char str1[size] = "Hello world i am fine";
- const int SIZE = 50;
- char str2[SIZE] = "It is str2 string";
- const int SiZe = 50;
- char str3[size] = "Bomonka 12345 45689";
- char ch;
- printf("Введите число:");
- scanf("%s",&ch);
- int start = 0, end = 0;
- printf("Введите Start:");
- scanf("%d",&start);
- printf("Введите end:");
- scanf("%d",&end);
- //printf("str1_len : %d\n",str1_len(str1));
- //printf("str2_len : %d\n",str2_len(str2));
- //printf("str_cpy: %s\n",str_cpy(str2,str1));
- //printf("str_cat: %s\n",str_cat(str1,str2));
- //printf("str_cmp: %d\n",str_cmp(str1,str2));
- //printf("ch_str:%d\n",ch_str(str1,ch));
- //printf("words_count:%d\n",words_count(str1));
- //printf("sum_of_digits:%d\n",sum_of_digits(str3));
- //printf("sum_of_decimal:%d\n",sum_of_decimal(str3));
- //reverse_str(str1); // не рабит(
- //printf("reverse_substr:%s\n",reverse_substr(str1,start,end));
- printf("longest_word:%d\n",longest_word(str2));
- printf("shorter_word:%d\n",shorter_word(str1));
- return 0;
- }
- int str1_len(char* str1)
- {
- int i = 0;
- while(str1[i]){
- i++;
- }
- return i;
- }
- int str2_len(char* str2)
- {
- int i = 0;
- while (str2[i]){
- i++;
- }
- return i;
- }
- int str3_len(char* str3)
- {
- int i = 0;
- while(str3[i]){
- i++;
- }
- return i;
- }
- char* str_cpy(char* str2, char* str1)
- {
- for(int j = 0;str2[j];j++){
- str2[j] = 0;
- for(int i = 0; str1[i];i++){
- str2[i] = str1[i];
- }
- }
- return str2;
- }
- char* str_cat(char* str1,char* str2)
- {
- int i = 0;
- int STr1_len = str1_len(str1);
- str1[STr1_len] = ' ';
- while (str1[i]){
- str1[i + STr1_len] = str2[i];
- i++;
- }
- return str1;
- }
- int str_cmp(char* str1,char* str2)
- {
- int i = 0;
- while (str1[i] && str2[i]){
- i++;
- }
- if((str1[i] - str2[i])== 0) return 1; else return 0;
- }
- int ch_str(char* str1, char ch)
- {
- int i = 0,n = -1;
- while(str1[i]){
- n++;
- if(str1[i] == ch)
- return n;
- i++;
- }
- return -1;
- }
- int words_count(char* str1)
- {
- int i = 0;
- int counter = 0,word = 0;
- char *dst = ".,-_\n\t!?&' '";
- while(str1[i]) {
- if(ch_str(dst,str1[i]) != -1) {
- if(word) {
- counter++;
- word = 0;
- }
- }
- else {
- word = 1;
- }
- i++;
- }
- if (word) counter++;
- return counter;
- }
- int sum_of_digits(char* str3)
- {
- int sum = 0;
- for(int i = 0; str3[i];i++){
- if(str3[i] >='0' && str3[i]<='9')
- {
- sum +=str3[i] - '0';
- }
- }
- return sum;
- }
- int sum_of_decimal(char* str3)
- {
- int sum = 0, counter = 0, i = 0;
- while (str3[i]){
- while(str3[i]>= '0' && str3[i]<= '9'){
- counter = counter * 10 + str3[i] - '0';
- i++;
- }
- i++;
- sum += counter;
- counter= 0;
- }
- return sum;
- }
- char* reverse_str(char* str1)
- {
- int i = 0;
- while (str1[i]){
- i++;
- }
- for(int j = i - 1; j >= 0; j--){
- printf("reverse_str:%d",str1[j]);
- }
- return 0;
- }
- void swap(char* a, char* b)
- {
- char temp = *a;
- *a = *b;
- *b = temp;
- }
- char* reverse_substr(char* str1, int start, int end)
- {
- while (start <= end){
- swap(&str1[start++],&str1[end--]);
- }
- return str1;
- }
- int longest_word(char* str2)
- {
- int i = 0,current_task = 0,max_task = 0,word = 0;
- char* dst = ".,-_\n\t!?&5' '";
- while(str2[i]){
- if(ch_str(dst,str2[i]) != -1) {
- if(word) {
- if (current_task > max_task)
- max_task = current_task;
- current_task = 0;
- word = 0;
- }
- } else {
- word = 1;
- current_task++;
- }
- i++;
- }
- if(word && current_task > max_task)
- max_task = current_task;
- return max_task;
- }
- int shorter_word(char* str)
- {
- int i = 0,current_task = 0,min_task = 0,word = 0;
- char* dst = ".,-_\n\t!?&5' '";
- while(str[i]){
- if(ch_str(dst,str[i]) != -1) {
- if(word) {
- if (current_task < min_task)
- min_task = current_task;
- current_task = 0;
- word = 0;
- }
- } else {
- word = 1;
- current_task++;
- }
- i++;
- }
- if(word && current_task < min_task)
- min_task = current_task;
- return min_task;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement