Additional Solutions Template TPEC
Additional Solutions Template TPEC
Closest Numbers
#include<stdio.h>
#include<stdlib.h>
int main(){
int i,n;
//input
scanf("%d",&n);
int *a=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
//sorting
//finding smallest
Maximizing XOR
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
int maxXor(int l, int r) {
Flipping Bits
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int t;
unsigned int n;
#include<stdio.h>
void quicksort(int x[100000],int first,int last){
int pivot,j,temp,i;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(x[i]<=x[pivot]&&i<last)
i++;
while(x[j]>x[pivot])
j--;
if(i<j){
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
quicksort(x,first,j-1);
quicksort(x,j+1,last);
}}
int main()
{
int n,k,i,avail=0,count=0;
int cost[n];
Greedy Florist
#include <stdio.h>
#include <stdlib.h>
int main()
{
scanf("%d %d\n",&n,&k);
for(i=0;i<n;i++)
scanf("%d",a+i);
int main(){
char* s = (char *)malloc(10240 * sizeof(char));
Mars Exploration
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
char* S = (char *)malloc(10240 * sizeof(char));
scanf("%s",S);
int i;
int count=0;
//……………..Insert Code Here…………….
printf("%d",count);
return 0;
}
Funny String
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int T, N, funny, i, r;
char S[10001];
scanf("%d\n", &T);
while (T--) {
scanf("%s\n", S);
N = strlen(S);
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int t;
long i=0;
unsigned int count=0;
char * c;
scanf("%d",&t);
c=(char *)malloc(sizeof(char)*(100002));
return 0;
}
Beautiful Binary String
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n;
scanf("%d",&n);
char* B = (char *)malloc(10240 * sizeof(char));
scanf("%s",B);
int i=0,count=0;
while(B[i]){
#include<stdio.h>
#include<math.h>