Paneer Love
Paneer Love
Paneer Love
1. Paneer Love
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d",&n);
int day[n],pcost[n],i;
for(i=0;i<n;i++)
scanf("%d %d",&day[i],&pcost[i]);
for(i=0;i<n-1;i++)
if(pcost[i]<pcost[i+1])
pcost[i+1]=pcost[i];
int result=0;
for(i=0;i<n;i++)
result=result+(day[i]*pcost[i]);
printf("%d",result);
return 0;
}
2. Number Pattern-9
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int s=1;s<=n-i;s++) printf(" ");
for (int j=1;j<=i;j++) printf("%d",j);
printf("\n");
}
return 0;
}
3. String Conversion:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
char str[10000];
scanf("%s",str);
int k,flag;
scanf("%d",&k);
if(k==1) printf("%s",str);
else{
for(int i=0;i<strlen(str);i+=(k-1)*2) printf("%c",str[i]);
for (int j=1;j<k-1;j++){
flag=1;
for(int i=j;i<strlen(str);){
printf("%c",str[i]);
if(flag==1) i+=(k-j-1)*2;
else i+=(k-1)*2-(k-j-1)*2;
flag=!flag;
}
}
for(int i=k-1;i<strlen(str);i+=(k-1)*2) printf("%c",str[i]);
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
#include <stdio.h>
static char *convert_To_Excel_Title(int column_no)
{
if (column_no <= 0) {
return "";
}
int i, j;
for (i = 0, j = len - 1; i < j; i++, j--) {
char c = result[i];
result[i] = result[j];
result[j] = c;
}
return result;
}
int main(void)
{
int n ;
scanf("%d",&n);
printf("%s ",convert_To_Excel_Title(n));
}
5. Dis.the Right Number
PYTHON.3
def titleToNumber(s):
result = 0;
for B in range(len(s)):
result *= 26;
result += ord(s[B]) - ord('A') + 1;
return result;
x = str(input())
print(titleToNumber(x));
6. Intro to Pointers
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int *var = (int*) malloc(sizeof(int));
scanf("%d", var );
printf("%d", *var);
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h> //this library contains the function malloc.
int main()
{
int i, j, N,flag=0,flag1=0;
scanf("%d", &N);
int *matrix[N];
for (i = 0; i < N; i++) matrix[i] = (int*) malloc(sizeof(int) * N);
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
scanf("%d", &matrix[i][j]);
}
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
if((i!=j)&&(N-1!=i+j)){
flag1++;
if(matrix[i][j]==0)
flag++;
}}
if(flag==flag1)
printf("yes\n");
else
printf("no\n");
}
int main()
{
char *str = (char*) malloc(sizeof(char) * 100);
scanf("%s",str);
str = strrev(str);
puts(str);
return 0;
}
PAGE.8
1. Rotating the Matrix
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int N;
scanf("%d",&N);
int a[N][N],b[N][N],i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
scanf("%d",&a[i][j]);
for(i=0;i<N;i++)
for(j=0;j<N;j++)
b[i][j]=a[N-j-1][i];
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("%d ",b[i][j]);
printf("\n");
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
2. Border Elements
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n,b;
scanf("%d %d",&n,&b);
int arr[n],i;
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=b-1;i<n;i+=b)
printf("%d ",arr[i]);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int rows,cols;
scanf("%d %d",&rows,&cols);
int arr[rows][cols],i,j;
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
scanf("%d",&arr[i][j]);
int rowIndex=0,colIndex=0;
while(rowIndex<rows&&colIndex<cols)
{
for(i=colIndex;i<cols;i++)
printf("%d ",arr[rowIndex][i]);
rowIndex++;//1
for(i=rowIndex;i<rows;i++)
printf("%d ",arr[i][cols-1]);
cols--;//2
if(rowIndex<rows)
{
for(i=cols-1;i>=colIndex;i--)
printf("%d ",arr[rows-1][i]);
rows--;//2
}
if(colIndex<cols)
{
for(i=rows-1;i>=rowIndex;i--)
printf("%d ",arr[i][colIndex]);
colIndex++;//1
}
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
---Pavan