Sunday, October 25, 2020

CODEFORCES- BEAUTIFUL MATRIX SOLUTION (24-10)

 CODEFORCES- BEAUTIFUL MATRIX SOLUTION

PROBLEM-  https://codeforces.com/problemset/problem/263/A

#include<stdio.h>
#include<stdlib.h>
int main(){
    int matrix[5][5];
    int ijx=0y=0move;
    for(i=0i<5i++){
        for(j=0j<5j++){
            scanf("%d", &matrix[i][j]);
        }
    }
    for(i=0i<5i++){
        for(j=0j<5j++){
            if(matrix[i][j]==1){
                x=i+1;
                y=j+1;
            }
        }
    }
    move = abs(x-3)+abs(y-3);
    printf("%d\n"move);
    return 0;
}

Thursday, October 22, 2020

22 - 10 - 20

 PROBLEM


SOLUTION - MY

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

//Complete the following function.

int marks_summation(int* marks, int number_of_students, char gender) {
    int sum = 0, i;
    for(i = 0;  i < number_of_students; i++){
        if(gender == 'b'){
            if(i%2 == 0)
                sum = sum + *(marks + i);
        }
        else {
            if(i%2 != 0)
                sum = sum + *(marks + i);
        }
    }
   return sum; 
}

int main() {
    int number_of_students;
    char gender;
    int sum;
  
    scanf("%d", &number_of_students);
    int *marks = (int *) malloc(number_of_students * sizeof (int));
 
    for (int student = 0; student < number_of_students; student++) {
        scanf("%d", (marks + student));
    }
    
    scanf(" %c", &gender);
    sum = marks_summation(marks, number_of_students, gender);
    printf("%d", sum);

PROBLEM SETTER SOLUTION

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int marks_summation(int* p, int number_of_students, char gender) {
    int s = 0, i = 0;
    if (gender == 'g') {
        i++;
    }
    for (; i < number_of_students; i = i+2) {
        s += p[i];       
    }
    return s;
}

22-10-20

PROBLEM
SOLUTION
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int find_nth_term (int n, int a, int b, int c) {
    if(n == 1) return a;
    if(n == 2) return b;
    if(n == 3) return c;
    return find_nth_term(n-1, a, b, c) + find_nth_term(n-2, a, b, c) + find_nth_term(n-3, a, b, c);
}

Wednesday, October 21, 2020

22-10 HACKERRANK C PROGRAMMING - DIGIT FREQUENCY

 22-10 HACKERRANK C PROGRAMMING - DIGIT FREQUENCY

PROBLEM 

SOLUTION


MY SOLUTION 

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
    char s[1000];
    int arr[10] = {0};
    scanf("%s", s);
    int i, j, num;
    for(i = 0;s[i] != '\0'; i++){
        num = s[i]-'0';
        // printf("%d\n", s[i]-'0');
        if((num>=0) && (num<=9)){
            // printf("%d ", num);
            for(j = 0; j < 10; j++){
                if(num == j){
                    arr[j]++;
                }
            }
        }
    }
    for(i=0; i < 10; i++){
        printf("%d ", arr[i]);
    }
    return 0;
}


DISCUSSION

int main() {
    int* nums = (int*) malloc(10 * sizeof(int));
    char c;
    
    for(int i = 0; i < 10; i++)
        *(nums+i) = 0;

    while(scanf("%c", &c) == 1)
        if(c >= '0' && c <= '9')
            (*(nums+(c-'0')))++;
    
    for(int i = 0; i < 10; i++)
        printf("%d ", *(nums+i));
    
    return EXIT_SUCCESS;
}

PROBLEM SETTERS SOLUTION

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
  
    char *s;
    s = malloc(1024 * sizeof(char));
    scanf("%s", s);
    s = realloc(s, strlen(s) + 1);
    int len = strlen(s), i;
    int arr[10];
    for(i = 0; i < 10; i++)
        arr[i] = 0;
    for(i = 0; i < len; i++) {
        if(s[i] >= '0' && s[i] <= '9') {
            arr[(int)(s[i] - '0')]++;
        }
    }
    for(i = 0; i < 10; i++)
        printf("%d ", arr[i]);
    printf("\n");
    free(s);
    return 0;
}


LEETCODE JUNE 2021 DAILY CODING CHALLENGE

 LEETCODE JUNE 2021 DAILY CODING CHALLENGE JUNE 1 JUNE 2 JUNE 3 JUNE 4 JUNE 5 Maximum Performance of a Team LINK You are given two integers ...