Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // uloha-6-1.c -- Tyzden 6 - Uloha 1
- // Michal Kovacik, 25.3.2014 08:58:27
- #include <stdio.h>
- #include <stdlib.h>
- int is_magic(int **a, int n)
- {
- int i, j, model = 0, riadok = 0, stlpec = 0, uhlopriecka1 = 0, uhlopriecka2 = 0;
- //prvy riadok ako vzor
- for(j=0; j<n; j++){
- model += a[0][j];
- }
- for(i=0; i<n; i++){
- riadok = stlpec = 0;
- for(j=0; j<n; j++){
- riadok += a[i][j];
- stlpec += a[j][i];
- if(j==i)
- uhlopriecka1 += a[i][j];
- if(i+j==n-1)
- uhlopriecka2 += a[i][j];
- }
- if(model!=riadok || model!=stlpec)
- return 0;
- }
- if(uhlopriecka1!=model || uhlopriecka2!=model)
- return 0;
- return 1;
- }
- int main()
- {
- int i, j, **s;
- s = (int**)malloc(3 * sizeof(int*));
- for (i = 0; i < 3; i++)
- s[i] = (int*)malloc(3 * sizeof(int));
- s[0][0] = 8; s[0][1] = 1; s[0][2] = 6;
- s[1][0] = 3; s[1][1] = 5; s[1][2] = 7;
- s[2][0] = 4; s[2][1] = 9; s[2][2] = 2;
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 3; j++)
- printf("%d ", s[i][j]);
- printf("\n");
- }
- if (is_magic(s, 3))
- printf("Je magicky.\n");
- else
- printf("NIE JE magicky!\n");
- return 0;
- }
- // uloha-6-2.c -- Tyzden 6 - Uloha 2
- // Michal Kovacik, 25.3.2014 09:27:13
- #include <stdio.h>
- void quickSort(int arr[], int from, int to){
- int i = from, j = to, pivot = arr[from], pom;
- if (to - from>0){
- while (i < j){
- while (arr[i] <= pivot)
- i++;
- while (arr[j] > pivot)
- j--;
- if (i < j){
- pom = arr[i];
- arr[i] = arr[j];
- arr[j] = pom;
- }
- }
- pom = arr[from];
- arr[from] = arr[j];
- arr[j] = pom;
- quickSort(arr, from, j - 1);
- quickSort(arr, i, to);
- }
- }
- int main(){
- int grafikon[10][99], i, j, cislo, pocty[10];
- for (i = 0; i < 10; i++){
- pocty[i] = 0;
- }
- while (scanf("%d", &cislo)!=EOF){
- i = cislo / 10;
- j = cislo % 10;
- grafikon[i][pocty[i]] = j;
- pocty[i]++;
- };
- for (i = 0; i < 10; i++){
- if (pocty[i]){
- quickSort(grafikon[i], 0, pocty[i]-1);
- printf("%d | ", i);
- for (j = 0; j < pocty[i]; j++){
- printf("%d", grafikon[i][j]);
- }
- putchar('\n');
- }
- }
- return 0;
- }
- // uloha-6-3.c -- Tyzden 6 - Uloha 3
- // Michal Kovacik, 25.3.2014 10:20:06
- #include <stdio.h>
- #include <string.h>
- int main(){
- char pole[1000];
- int i;
- while (scanf("%s", pole) != EOF){
- if (strchr(pole, '*') != NULL){
- printf("%s\n", pole);
- for (i = 0; i < strlen(pole); i++){
- if (pole[i] == '*')
- putchar('^');
- else
- putchar(' ');
- }
- putchar('\n');
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement