Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----Длина текста----
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main() {
- char a[10000];
- FILE* fp;
- fp = fopen("input.txt", "r");
- int count = 0;
- while (!feof (fp)) {
- if (fgets(a, 9999, fp)) count+=strlen(a);
- }
- printf("%i", count);
- return 0;
- }
- -----Простая замена-----
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main() {
- char a[10000];
- gets(a);
- for (int i=0;i<strlen(a);++i)
- {
- if (a[i]=='A'){
- a[i]='b';
- continue;
- }
- if (a[i]=='a'){
- a[i]='B';
- continue;
- }
- if (a[i]=='B'){
- a[i]='a';
- continue;
- }
- if (a[i]=='b'){
- a[i]='A';
- continue;
- }
- }
- printf("%s",a );
- return 0;
- }
- ------Подсчет числа способов 2-------
- #include <stdlib.h>
- #include <stdio.h>
- int main() {
- int count=0;
- char a[1000];
- scanf("%[^\n]s",a);
- int i=0;
- int fl_slovo=0;
- while(a[i]!='\0' && a[i]!='\n')
- {
- if(a[i]!=' ' )
- {
- if (fl_slovo==0)
- {
- fl_slovo=1;
- count++;
- }
- }
- else{
- fl_slovo=0;
- }
- i++;
- }
- printf("%i",count);
- return 0;
- }
- -------Очистка строки--------
- 1)
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- char a[1000];
- gets(a);
- int i = 0;
- int fl = 0;
- int len = 0;
- while (a[i] != '\0')
- {
- len++;
- i++;
- }
- i = 0;
- for (int i = 0; i < len; ++i)
- {
- if (a[i] == ' ')
- {
- int k = i + 1;
- while (a[k] == ' ')
- {
- for (int j = k; j < len; ++j)
- {
- a[j] = a[j + 1];
- }
- a[len - 1] = '\0';
- len--;
- }
- }
- }
- if (a[0] == ' ')
- {
- for (int j = 0; j < len; ++j)
- {
- a[j] = a[j + 1];
- }
- }
- if (a[len - 1] == ' ')
- {
- a[len - 1] = '\0';
- len--;
- }
- printf("%s", a);
- return 0;
- }
- 2)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main() {
- char a[1000];
- char buffer[1000];
- gets(a);
- int len = strlen(a);
- int fl = 1;
- int iter = 0;
- for (int i = 0; i < len; ++i)
- {
- if (a[i] == ' ')
- {
- fl = 1;
- continue;
- }
- if (fl == 1)
- {
- int flag_arab = 0;
- int count = 0;
- for (int j = i; a[j] != ' ' && j < len; ++j)
- {
- count++;
- if (a[j] == '1' || a[j] == '2' || a[j] == '3' || a[j] == '4' || a[j] == '5' || a[j] == '6' || a[j] == '7' || a[j] == '8' || a[j] == '9' || a[j] == '0')
- {
- flag_arab = 1;
- }
- }
- if (flag_arab != 1)
- {
- for (int j = i; j < count + i; j++)
- {
- buffer[iter] = a[j];
- iter++;
- }
- buffer[iter] = ' ';
- iter++;
- buffer[iter] = '\0';
- }
- fl = 0;
- }
- }
- if (buffer[iter - 1] == ' ')
- {
- buffer[iter - 1] = '\0';
- iter--;
- }
- printf("%s", buffer );
- return 0;
- }
- 3)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int main() {
- char a[1000];
- char buffer[1000];
- gets(a);
- int len = strlen(a);
- int fl = 1;
- int iter = 0;
- for (int i = 0; i < len; ++i)
- {
- if (a[i] == ' ')
- {
- fl = 1;
- continue;
- }
- if (fl == 1)
- {
- int flag_arab = 0;
- int count = 0;
- for (int j = i; a[j] != ' ' && j < len; ++j)
- {
- count++;
- if (!isalnum(a[j]) && a[j]!='–')
- {
- flag_arab = 1;
- }
- }
- if (flag_arab != 1)
- {
- for (int j = i; j < len && j < count + i; j++)
- {
- buffer[iter] = a[j];
- iter++;
- }
- buffer[iter] = ' ';
- iter++;
- buffer[iter] = '\0';
- }
- fl = 0;
- }
- }
- if (buffer[iter - 1] == ' ')
- {
- buffer[iter - 1] = '\0';
- iter--;
- }
- printf("%s", buffer );
- return 0;
- }
- --__------- Выжимки----------
- 1)Числовая
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int comp(const int *i,const int *j)
- {
- return *i-*j;
- }
- int main() {
- char a[10000];
- char buffer[10000];
- int chisla[1000];
- int counter=0;
- gets(a);
- int len = strlen(a);
- int fl = 1;
- int iter = 0;
- for (int i = 0; i < len; ++i)
- {
- if (a[i] == ' ')
- {
- fl = 1;
- continue;
- }
- if (fl == 1)
- {
- int flag_arab = 0;
- int count = 0;
- for (int j = i; a[j] != ' ' && j < len; ++j)
- {
- count++;
- if (!isdigit(a[j]) && a[j]!='+' &&a[j]!='-')
- {
- flag_arab = 1;
- }
- }
- if (flag_arab != 1)
- {
- for (int j = i; j < count + i; j++)
- {
- buffer[iter] = a[j];
- iter++;
- }
- buffer[iter] = '\0';
- chisla[counter]=atoi(buffer);
- buffer[0]='\0';
- iter=0;
- counter++;
- }
- fl = 0;
- }
- }
- qsort(chisla, counter, sizeof (int), (int(*) (const void *, const void *)) comp);
- for(int i=0;i<counter;++i)
- {
- if(i!=counter-1){printf("%i ",chisla[i]);}
- else printf("%i",chisla[i]);
- }
- return 0;
- }
- 3 Латинская)
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int main() {
- char a[10001];
- char** chisla = (char**) calloc(10000, sizeof(char*));
- scanf("%[^\n]s",a);
- int len = strlen(a);
- int fl = 1;
- int iter = 0;
- int ind = 0;
- for (int i = 0; i < len; ++i)
- {
- if (isspace(a[i]))
- {
- fl = 1;
- continue;
- }
- if (fl == 1)
- {
- int flag_arab = 0;
- int count = 0;
- for (int j = i; (!isspace(a[j])) && j < len; ++j)
- {
- count++;
- if (!isalpha(a[j]))
- {
- flag_arab = 1;
- }
- }
- if (!flag_arab)
- {
- chisla[ind] = (char*)calloc(10000, sizeof(char));
- for (int j = i; j < count + i; j++)
- {
- chisla[ind][iter] = a[j];
- iter++;
- }
- chisla[ind][iter] = '\0';
- ind++;
- iter = 0;
- }
- fl = 0;
- }
- }
- for (int i = 0; i < ind - 1; ++i)
- {
- for (int j = 0; j < ind - i - 1; ++j)
- {
- char buffer_one[1000];
- char buffer_two[1000];
- strcpy(buffer_one,chisla[j]);
- strcpy(buffer_two,chisla[j+1]);
- for (int s=0;s<strlen(buffer_one);++s)
- {
- buffer_one[s]=tolower(buffer_one[s]);
- }
- for (int s=0;s<strlen(buffer_two);++s)
- {
- buffer_two[s]=tolower(buffer_two[s]);
- }
- if(strcmp(buffer_one,buffer_two)>0)
- {
- char* buf = chisla[j];
- chisla[j]=chisla[j+1];
- chisla[j+1]=buf;
- }
- }
- }
- for (int i = 0; i < ind; ++i)
- {
- if (i != ind - 1) {printf("%s ", chisla[i]);}
- else printf("%s", chisla[i]);
- }
- return 0;
- }
- =====Простой переворот===
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- char a[1000];
- gets(a);
- int i = 0;
- int fl = 0;
- int len = 0;
- while (a[i] != '\0')
- {
- len++;
- i++;
- }
- for(int j=0;j<len*0.5;++j)
- {
- int temp=a[j];
- a[j]=a[len-1-j];
- a[len-1-j]=temp;
- }
- printf("%s", a);
- return 0;
- }
- ======Непростой переворот 1-2=======
- 1))))
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- char a[1000];
- char dop[100];
- gets(a);
- int i = 0;
- int len = 0;
- while (a[i] != '\0')
- {
- len++;
- i++;
- }
- int fl = 1;
- for (int j = 0; j < len; ++j)
- {
- if (a[j] == ' ')
- {
- fl = 1;
- continue;
- }
- if (a[j] != ' ' && fl == 1)
- {
- int count = 0;
- for (int o = j; a[o] != ' ' && a[o]!='\0'; ++o)
- {
- dop[count] = a[o];
- count++;
- }
- dop[count]='\0';
- for (int o = 0; o < count * 0.5; o++)
- {
- char temp = dop[o];
- dop[o] = dop[count - 1 - o];
- dop[count - 1 - o] = temp;
- }
- int f=0;
- for (int o = j; o < count+j; o++)
- {
- a[o] = dop[f];
- f++;
- }
- j+=count;
- dop[0]='\0';
- }
- }
- printf("%s", a);
- return 0;
- }
- 2))))))))))
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- char a[10000];
- char dop[10000];
- gets(a);
- int u = 0;
- int len = 0;
- while (a[u] != '\0')
- {
- len++;
- u++;
- }
- for (int i = 0; i < len; ++i)
- {
- if (a[i] == ' ')
- {
- int k = i + 1;
- while (a[k] == ' ')
- {
- for (int j = k; j < len; ++j)
- {
- a[j] = a[j + 1];
- }
- a[len - 1] = '\0';
- len--;
- }
- }
- }
- if (a[0] == ' ')
- {
- for (int j = 0; j < len; ++j)
- {
- a[j] = a[j + 1];
- }
- }
- if (a[len - 1] == ' ')
- {
- a[len - 1] = '\0';
- len--;
- }
- int fl = 1;
- for (int j = 0; j < len; ++j)
- {
- if (a[j] == ' ')
- {
- fl = 1;
- continue;
- }
- if (a[j] != ' ' && fl == 1)
- {
- int count = 0;
- for (int o = j; a[o] != ' ' && a[o]!='\0'; ++o)
- {
- dop[count] = a[o];
- count++;
- }
- dop[count]='\0';
- for (int o = 0; o < count * 0.5; o++)
- {
- char temp = dop[o];
- dop[o] = dop[count - 1 - o];
- dop[count - 1 - o] = temp;
- }
- int f=0;
- for (int o = j; o < count+j; o++)
- {
- a[o] = dop[f];
- f++;
- }
- j+=count;
- dop[0]='\0';
- }
- }
- printf("%s", a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement