Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.priklad
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #define ABC ('Z' - 'A' +1)
- void vynuluj(int *buf, int n);
- int main(){
- int histogram[ABC], i, j, index[ABC], max, *indexOfPismeno;
- char slovo[100];
- while (scanf("%s", slovo) != EOF){
- vynuluj(histogram, ABC);
- vynuluj(index, ABC);
- i = j = max = 0;
- while (slovo[i] != '\0')
- histogram[(tolower(slovo[i++])) - 'a']++;
- for (i = 0; i < ABC; i++){
- if (histogram[i]>max){
- max = histogram[i];
- }
- }
- for (i = 0; i < ABC; i++){
- if (max == histogram[i]){
- index[j] = i;
- j++;
- }
- }
- if (j > 0){
- indexOfPismeno = (strrchr(slovo, index[0] + 'a'));
- for (i = 1; i < j; i++){
- if ((strrchr(slovo, index[i] + 'a'))>indexOfPismeno)
- indexOfPismeno = (strrchr(slovo, index[i] + 'a'));
- }
- }
- printf("%c %d\n", *indexOfPismeno, max);
- }
- return 0;
- }
- void vynuluj(int *buf, int n){
- int i;
- for (i = 0; i < n; i++)
- buf[i] = 0;
- }
- //2.priklad
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int n, *pole, suma, i=0, j=0, k, pomsuma, def = -1, defi = -1;
- scanf("%d", &n);
- pole = (int*)malloc(n*sizeof(int));
- for (i = 0; i < n; i++){
- scanf("%d", (pole + i));
- }
- scanf("%d", &suma);
- i = 0;
- while(i<n){
- pomsuma = 0;
- for (k = j; k <= i; k++)
- pomsuma += (*(pole + k));
- if (i== n-1){
- j++;
- i = j;
- continue;
- }
- if (pomsuma == suma){
- if (def != -1){
- def = (def < i - j) ? def : i - j;
- defi = (def == i - j) ? j : defi;
- }
- else{
- def = i - j;
- defi = j;
- }
- }
- i++;
- }
- if (defi == -1)
- printf("Hladana podpostupnost v poli neexistuje\n");
- else{
- for (i = defi; i <= defi + def; i++)
- printf("%d ", pole[i]);
- putchar('\n');
- }
- return 0;
- }
- //3.priklad
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int n, *pole, suma, i=0, j=0, k, pomsuma, def = -1, defi = -1;
- scanf("%d", &n);
- pole = (int*)malloc(n*sizeof(int));
- for (i = 0; i < n; i++){
- scanf("%d", (pole + i));
- }
- scanf("%d", &suma);
- i = 0;
- while(i<n){
- pomsuma = 0;
- for (k = j; k <= i; k++)
- pomsuma += (*(pole + k));
- if (i== n-1){
- j++;
- i = j;
- continue;
- }
- if (pomsuma == suma){
- if (def != -1){
- def = (def > i - j) ? def : i - j;
- defi = (def == i - j) ? j : defi;
- }
- else{
- def = i - j;
- defi = j;
- }
- }
- i++;
- }
- if (defi == -1)
- printf("Hladana podpostupnost v poli neexistuje\n");
- else{
- for (i = defi; i <= defi + def; i++)
- printf("%d ", pole[i]);
- putchar('\n');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement