├── .gitignore ├── ATM HS08TEST.c ├── Add Two Numbers FLOW001.c ├── Alternating subarray prefix ALTARY.c ├── Chef And Coloring COLOR.c ├── Chef And Magical CHEFPATH.c ├── Chef and Ballons CHBLLNS.c ├── Chef and Dolls MISSP.c ├── Chef and Two Strings CHEFSTLT.c ├── Cooking Machine COOKMACH.c ├── Enormous Input Test INTEST.c ├── Factorial FCTRL.c ├── Farmer And His Plot RECTSQ.c ├── Fibonacci Queries FIBQ.c ├── Find Remainder FLOW002.c ├── Finding Square Roots FSQRT.c ├── First and Last Digit FLOW004.c ├── Good Joke RRJOKE.c ├── Help Watson Escape BIPIN3.c ├── Life, the Universe, and Everything TEST.c ├── Lucky Four LUCKFOUR.c ├── Mahasena AMR15A.c ├── Malvika is peculiar about color of balloons Solved CHN09.c ├── Maximum K Sums KSUM.c ├── Minimum Maximum MNMX.c ├── Number Mirror START01.c ├── Odd Divisors ODDDIV.c ├── Packaging Cupcakes MUFFINS3.c ├── Palindromic substrings STRPALIN.c ├── Piece of cake LCH15JAB.c ├── README.md ├── Reverse The Number FLOW007.c ├── Simple Multiplication MULTISRM.c ├── Small factorials FCTRL2.c ├── Sum of Digits FLOW006.c ├── Sum of palindromic numbers SPALNUM.c ├── The Lead Game TLG.c ├── Turbo Sort TSORT.c └── factorial_cpp.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | -------------------------------------------------------------------------------- /ATM HS08TEST.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int w; 6 | float t; 7 | scanf("%d%f",&w,&t); 8 | if(w+0.5>t) 9 | { 10 | printf("%.2f",t); 11 | } 12 | else if(w%5!=0) 13 | printf("%.2f",t); 14 | else 15 | printf("%.2f",t-w-0.5); 16 | 17 | return 0 ; 18 | } -------------------------------------------------------------------------------- /Add Two Numbers FLOW001.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int t; scanf("%d",&t); 6 | while(t--) 7 | { 8 | long int a,b; 9 | scanf("%ld %ld",&a,&b); printf("%ld\n",a+b); 10 | } 11 | } -------------------------------------------------------------------------------- /Alternating subarray prefix ALTARY.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 100000 3 | 4 | int main() 5 | { 6 | int t; 7 | scanf("%d", &t); 8 | while(t--) 9 | { 10 | int i, j, n, count[MAX]={0}; 11 | long long arr[MAX]; 12 | scanf("%d", &n); 13 | for(i=0; i=0; i--) 17 | { 18 | if((arr[i]*arr[i+1])<=0) 19 | count[i]=count[i+1]+1; 20 | else 21 | count[i]=1; 22 | } 23 | for(i=0; i 2 | 3 | int main(void) { 4 | long int t; scanf("%d",&t); 5 | while(t--) 6 | { 7 | long int n,i,max=0; scanf("%ld",&n); 8 | char s[100010]={'\0'}; 9 | scanf("%s",s); 10 | long int c[3]; 11 | for(i=0;i<3;i++) c[i]=0; 12 | for(i=0;i 2 | 3 | int main(void) { 4 | int t; scanf("%d",&t); 5 | while(t--) 6 | { 7 | long long int n,m; scanf("%lld%lld",&n,&m); 8 | if(n*m==2) printf("Yes\n"); 9 | else if((n*m)%2!=0||(n==1||m==1)) printf("No\n"); 10 | else printf("Yes\n"); 11 | } 12 | // your code goes here 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Chef and Ballons CHBLLNS.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void quick_sort (long long int *data, long long int n) 4 | { 5 | long long int i, j, p, t; 6 | if (n < 2) 7 | return; 8 | p = data[n / 2]; 9 | for (i = 0, j = n - 1;; i++, j--) { 10 | while (data[i] < p) 11 | i++; 12 | while (p < data[j]) 13 | j--; 14 | if (i >= j) 15 | break; 16 | t = data[i]; 17 | data[i] = data[j]; 18 | data[j] = t; 19 | } 20 | quick_sort(data, i); 21 | quick_sort(data + i, n - i); 22 | return; 23 | } 24 | int main(void) { 25 | long int t; scanf("%ld",&t); 26 | while(t--) 27 | { 28 | long long int c[3],k; 29 | scanf("%lld%lld%lld",&c[0],&c[1],&c[2]); 30 | quick_sort(c,3); 31 | scanf("%lld",&k); 32 | //printf("%lld%lld%lld\n",c[0],c[1],c[2]); 33 | if(k<=c[0]) printf("%lld\n",(k-1)*3+1); 34 | else if(k>c[0]&&k<=c[1]) printf("%lld\n",c[0]*3+(k-1-c[0])*2+1); 35 | else if(k>c[1]&&k<=c[2]) printf("%lld\n",c[0]+k+c[1]); 36 | } 37 | // your code goes here 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Chef and Dolls MISSP.c: -------------------------------------------------------------------------------- 1 | /*Chef is fan of pairs and he likes all things that come in pairs. 2 | He even has a doll collection in which all dolls have paired. 3 | One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!! 4 | Help chef find which type of doll is missing.. 5 | */ 6 | #include 7 | 8 | int main(void) 9 | { 10 | int t,n,a,res; 11 | scanf("%d",&t); 12 | while(t--) 13 | { 14 | res=0; 15 | scanf("%d",&n); 16 | while(n--) 17 | { 18 | scanf("%d",&a); 19 | res^=a; 20 | } 21 | printf("%d\n",res); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Chef and Two Strings CHEFSTLT.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int t; scanf("%d",&t); 5 | while(t--) 6 | { 7 | //int n,i,k; scanf("%d%d",&n,&k); 8 | char s1[200],s2[200]; 9 | scanf("%s",s1); 10 | scanf("%s",s2); 11 | int c1=0,c2=0,i; 12 | for(i=0;i 20 | #include 21 | 22 | int main() 23 | { 24 | int t; 25 | long long int A, B, count = 0; 26 | scanf("%d", &t); 27 | while (t--) 28 | { 29 | scanf("%lld %lld", &A, &B); 30 | while (B%A != 0) 31 | { 32 | A = A / 2; 33 | count++; 34 | } 35 | while (A != B) 36 | { 37 | A = A * 2; 38 | count++; 39 | } 40 | printf("%lld\n", count); 41 | count = 0; 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Enormous Input Test INTEST.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n,k,t; 6 | int c=0,i; 7 | scanf("%d %d",&n,&k); 8 | i=1; 9 | while(i<=n) 10 | { 11 | scanf("%d\n",&t); 12 | if(t%k==0) c++; 13 | i++; 14 | } 15 | printf("%d",c); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Factorial FCTRL.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int a,b,c,t; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | scanf("%d",&a); 10 | c=1; 11 | b=0; 12 | while(a/c>0) 13 | { 14 | c=c*5; 15 | b=b+(a/c); 16 | } 17 | printf("%d\n",b); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Farmer And His Plot RECTSQ.c: -------------------------------------------------------------------------------- 1 | /*Santosh has a farm at Byteland. He has a very big family to look after. 2 | His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, 3 | he decides to sell some parts of his plots. The specialty of his plot is that it is rectangular in nature. 4 | Santosh comes to know that he will get more money if he sells square shaped plots. So keeping this in mind, 5 | he decides to divide his plot into minimum possible square plots so that he can get maximum profit out of this. 6 | So your task is to find the minimum number of square plots that can be formed out of the rectangular plot. 7 | */ 8 | #include 9 | int gcd(int a,int b) 10 | { 11 | if(b==0) 12 | return a; 13 | else 14 | return gcd(b,a%b); 15 | } 16 | main() 17 | { 18 | int t,a,b,c; scanf("%d",&t); 19 | while(t--) 20 | { 21 | scanf("%d%d",&a,&b); 22 | c=gcd(a,b); 23 | printf("%d\n",(a*b)/(c*c)); 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Fibonacci Queries FIBQ.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MOD 1000000007 4 | long long *a; 5 | struct matrix 6 | { 7 | long long aux[2][2]; 8 | }T[400020], result; 9 | 10 | void matrix_power(long long n,long long ar[2][2]) 11 | { 12 | long long p,q,r,s; 13 | if(n==0||n==1) 14 | return; 15 | long long Mat[2][2]={{1,1},{1,0}}; 16 | matrix_power(n/2,ar); 17 | p=((ar[0][0]*ar[0][0])%MOD+(ar[0][1]*ar[1][0])%MOD)%MOD; 18 | q=((ar[0][0]*ar[0][1])%MOD+(ar[0][1]*ar[1][1])%MOD)%MOD; 19 | r=((ar[1][0]*ar[0][0])%MOD+(ar[1][1]*ar[1][0])%MOD)%MOD; 20 | s=((ar[1][0]*ar[0][1])%MOD+(ar[1][1]*ar[1][1])%MOD)%MOD; 21 | ar[0][0]=p; 22 | ar[0][1]=q; 23 | ar[1][0]=r; 24 | ar[1][1]=s; 25 | if(n%2==1) 26 | { 27 | p=((ar[0][0]*Mat[0][0])%MOD+(ar[0][1]*Mat[1][0])%MOD)%MOD; 28 | q=((ar[0][0]*Mat[0][1])%MOD+(ar[0][1]*Mat[1][1])%MOD)%MOD; 29 | r=((ar[1][0]*Mat[0][0])%MOD+(ar[1][1]*Mat[1][0])%MOD)%MOD; 30 | s=((ar[1][0]*Mat[0][1])%MOD+(ar[1][1]*Mat[1][1])%MOD)%MOD; 31 | ar[0][0]=p; 32 | ar[0][1]=q; 33 | ar[1][0]=r; 34 | ar[1][1]=s; 35 | } 36 | } 37 | 38 | void matrix_multiply(long long a[2][2],long long b[2][2],long long ar[2][2]){ 39 | ar[0][0]= ((a[0][0]*b[0][0])%MOD+(a[0][1]*b[1][0])%MOD)%MOD; 40 | ar[0][1]= ((a[0][0]*b[0][1])%MOD+(a[0][1]*b[1][1])%MOD)%MOD; 41 | ar[1][0]= ((a[1][0]*b[0][0])%MOD+(a[1][1]*b[1][0])%MOD)%MOD; 42 | ar[1][1]= ((a[1][0]*b[0][1])%MOD+(a[1][1]*b[1][1])%MOD)%MOD; 43 | } 44 | 45 | void build_Seg(long long start,long long end,long long node){ 46 | if(start==end) 47 | { 48 | long long ar[2][2]; 49 | // ar=(long long **)malloc(sizeof(long long *)*2); 50 | // ar[0]=(long long *)malloc(sizeof(long long)); 51 | // ar[1]=(long long *)malloc(sizeof(long long)); 52 | ar[0][0]=1; 53 | ar[0][1]=1; 54 | ar[1][0]=1; 55 | ar[1][1]=0; 56 | matrix_power(a[start],ar); 57 | T[node].aux[0][1]=ar[0][1]; 58 | T[node].aux[1][0]=ar[1][0]; 59 | T[node].aux[0][0]=(ar[0][0]+1)%MOD; 60 | T[node].aux[1][1]=(ar[1][1]+1)%MOD; 61 | //free(ar); 62 | } 63 | else 64 | { 65 | long long mid=(start+end)/2; 66 | build_Seg(start,mid,2*node+1); 67 | build_Seg(mid+1,end,2*node+2); 68 | matrix_multiply( T[2*node+1].aux, T[2*node+2].aux,T[node].aux); 69 | } 70 | } 71 | void update(long long start,long long end,long long index ,long long node ){ 72 | if(start==end){ 73 | long long ar[2][2]; 74 | // ar=(long long **)malloc(sizeof(long long *)*2); 75 | // ar[0]=(long long *)malloc(sizeof(long long)); 76 | // ar[1]=(long long *)malloc(sizeof(long long)); 77 | ar[0][0]=1; 78 | ar[0][1]=1; 79 | ar[1][0]=1; 80 | ar[1][1]=0; 81 | matrix_power(a[start],ar); 82 | T[node].aux[0][1]=ar[0][1]; 83 | T[node].aux[1][0]=ar[1][0]; 84 | T[node].aux[0][0]=(ar[0][0]+1)%MOD; 85 | T[node].aux[1][1]=(ar[1][1]+1)%MOD; 86 | //free(ar); 87 | } 88 | else{ 89 | long long mid=(end+start)/2; 90 | if(index >=start && index<=mid) 91 | update(start,mid,index,2*node+1); 92 | else 93 | update(mid+1,end,index,2*node+2); 94 | matrix_multiply( T[2*node+1].aux, T[2*node+2].aux,T[node].aux); 95 | } 96 | } 97 | struct matrix query(long long start,long long end,long long l,long long r,long long node){ 98 | if(l<=start && r>=end) 99 | return T[node]; 100 | if(rend){ 101 | struct matrix tmp; 102 | tmp.aux[0][0]=1; 103 | tmp.aux[1][1]=1; 104 | tmp.aux[0][1]=0; 105 | tmp.aux[1][0]=0; 106 | return tmp; 107 | } 108 | else{ 109 | long long mid=(end+start)/2; 110 | struct matrix q1=query(start,mid,l,r,2*node+1); 111 | struct matrix q2=query(mid+1,end,l,r,2*node+2); 112 | matrix_multiply(q1.aux,q2.aux,result.aux); 113 | return result; 114 | } 115 | } 116 | int main(){ 117 | char ch; 118 | long long i,j,l,r,n,m; 119 | scanf("%lld%lld",&n,&m); 120 | a=(long long *)malloc(sizeof(long long)*(n+1)); 121 | for(i=0;i 2 | 3 | int main (void) 4 | { 5 | int t; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | int a,b; 10 | scanf("%d %d",&a,&b); 11 | printf("%d\n",a%b); 12 | } 13 | } -------------------------------------------------------------------------------- /Finding Square Roots FSQRT.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | { 6 | int t,q; 7 | scanf("%d",&t); 8 | for(q=0;q=a[j-1]) 22 | { 23 | t=a[j]; 24 | a[j]=a[j-1]; 25 | a[j-1]=t; 26 | } 27 | } 28 | 29 | } 30 | printf("%d\n",a[n-1]+a[n-2]); 31 | } 32 | } -------------------------------------------------------------------------------- /First and Last Digit FLOW004.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int t; scanf("%d",&t); 7 | char a[10]; 8 | while(t--) 9 | { 10 | scanf("%s",a); 11 | printf("%ld\n",(a[0]-'0' + a[strlen(a)-1] - '0')); 12 | } 13 | } -------------------------------------------------------------------------------- /Good Joke RRJOKE.c: -------------------------------------------------------------------------------- 1 | /* Vadim and Roman like discussing challenging problems with each other. One day Vadim told his friend following problem: 2 | Given N points on a plane. Each point p is defined by it's two integer coordinates — px and py. 3 | The distance between points a and b is min(|ax - bx|, |ay - by|). 4 | You should choose a starting point and make a route visiting every point exactly once, 5 | i.e. if we write down numbers of points in order you visit them we should obtain a permutation. 6 | Of course, overall distance walked should be as small as possible. The number of points may be up to 40. 7 | "40? Maybe 20? Are you kidding?" – asked Roman. "No, it's not a joke" – replied Vadim. 8 | So Roman had nothing to do, but try to solve this problem. 9 | Since Roman is really weak in problem solving and you are the only friend, except Vadim, 10 | with whom Roman can discuss challenging tasks, he has nobody else to ask for help, but you! 11 | */ 12 | #include 13 | main() 14 | { 15 | int t,n; scanf("%d",&t); 16 | while(t--) 17 | { 18 | int ans=0,i; 19 | scanf("%d",&n); 20 | for(i=1;i<=n;i++) 21 | { 22 | int x,y; scanf("%d%d",&x,&y); 23 | ans^=i; 24 | } 25 | printf("%d\n",ans); 26 | } 27 | return; 28 | } -------------------------------------------------------------------------------- /Help Watson Escape BIPIN3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define max 1000000007 3 | 4 | long long int power(long long int x,long long int y) 5 | { 6 | long long int temp; 7 | if( y == 0) 8 | return 1; 9 | temp = power(x, y/2)%max; 10 | if (y%2 == 0) 11 | return (temp*temp)%max; 12 | else 13 | return (((x*temp)%max)*temp)%max; 14 | } 15 | int main() 16 | { 17 | int t;scanf("%d",&t); 18 | while(t--) 19 | { long long int n,k,ans; 20 | scanf("%lld%lld",&n,&k); 21 | if(n==1 && k==1) 22 | printf("1\n"); 23 | else if(k==1) 24 | printf("0\n"); 25 | else 26 | { ans=(k*(power(k-1,n-1)%max))%(max); 27 | printf("%lld\n",ans); 28 | } 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Life, the Universe, and Everything TEST.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { int x,i; 3 | scanf("%d",&x); 4 | if((x<100)&&(x!=42)) 5 | { 6 | printf("%d \n",x); 7 | return main(); 8 | } 9 | return 0; 10 | } -------------------------------------------------------------------------------- /Lucky Four LUCKFOUR.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | { 6 | int t; char a[15]; 7 | scanf("%d",&t); 8 | while(t--) 9 | { 10 | scanf("%s",&a); 11 | int c=0,k; 12 | for(k=0;k 11 | 12 | int main(void) { 13 | int n,i,c1=0,c2=0; scanf("%d",&n); 14 | int a[n]; 15 | for(i=0;ic2) printf("READY FOR BATTLE\n"); 22 | else printf("NOT READY\n"); 23 | // your code goes here 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Malvika is peculiar about color of balloons Solved CHN09.c: -------------------------------------------------------------------------------- 1 | /*Little Malvika is very peculiar about colors. On her birthday, her mom wanted to buy balloons for decorating the house. 2 | So she asked her about her color preferences. The sophisticated little person that Malvika is, she likes only two colors — amber and brass. 3 | Her mom bought n balloons, each of which was either amber or brass in color. You are provided this information in a string s consisting of 4 | characters 'a' and 'b' only, where 'a' denotes that the balloon is amber, where 'b' denotes it being brass colored. 5 | When Malvika saw the balloons, she was furious with anger as she wanted all the balloons of the same color. 6 | In her anger, she painted some of the balloons with the opposite color (i.e., she painted some amber ones brass and vice versa) 7 | to make all balloons appear to be the same color. As she was very angry, it took her a lot of time to do this, 8 | but you can probably show her the right way of doing so, thereby teaching her a lesson to remain calm in difficult situations, 9 | by finding out the minimum number of balloons needed to be painted in order to make all of them the same color. */ 10 | 11 | #include 12 | 13 | int main(void) { 14 | int t; scanf("%d",&t); 15 | while(t--) 16 | { 17 | char s[100]; scanf("%s",s); 18 | int i,c1=0,c2=0; 19 | for(i=0;i=c2) printf("%d\n",c2); 25 | else printf("%d\n",c1); 26 | } 27 | // your code goes here 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Maximum K Sums KSUM.c: -------------------------------------------------------------------------------- 1 | #include 2 | long long a[100001],p[100001],w[100001]; 3 | int main() 4 | { 5 | int t,n,k,i,j; 6 | scanf("%d%d",&n,&k); 7 | long long s=0; 8 | for(i=1;i<=1e5;i++) 9 | { 10 | scanf("%lld",&a[i]); 11 | p[i]=p[i-1]+a[i]; 12 | } 13 | long long m=n; 14 | for(i=1;i<=k;i++) 15 | { 16 | long long m=n; 17 | for(j=n;j>=1;j--) 18 | { 19 | if(p[j]-p[w[j]]>p[m]-p[w[m]]) 20 | { 21 | m=j; 22 | } 23 | if(w[j]==0) 24 | break; 25 | } 26 | printf("%lld ",p[m]-p[w[m]]); 27 | w[m]++; 28 | } 29 | } -------------------------------------------------------------------------------- /Minimum Maximum MNMX.c: -------------------------------------------------------------------------------- 1 | /*Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. 2 | He wants to perform the following operation on his array A. 3 | 4 | Select a pair of adjacent integers and remove the larger one of these two. 5 | This decreases the array size by 1. Cost of this operation will be equal to the smaller of them. 6 | 7 | Find out minimum sum of costs of operations needed to convert the array into a single element 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | int main(void) { 14 | int t; scanf("%d",&t); 15 | while(t--) 16 | { 17 | unsigned int n,i;scanf("%u",&n); 18 | unsigned int a[n],min=100001; 19 | for(i=0;ia[i]) min=a[i]; 23 | } 24 | printf("%u\n",min*(n-1)); 25 | } 26 | // your code goes here 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Number Mirror START01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a[50]; 6 | scanf("%s",a); 7 | printf("%s",a); 8 | } -------------------------------------------------------------------------------- /Odd Divisors ODDDIV.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int i,t,l,r; 5 | long long int sum2,sum1; 6 | scanf("%d",&t); 7 | while(t--){ 8 | sum2 =0;sum1 = 0; 9 | scanf("%d%d",&l,&r); 10 | for(i=1;i<=r;i=i+2) 11 | sum2 = sum2 + i*(r/i); 12 | for(i=1;i<=l-1;i=i+2) 13 | sum1 = sum1 + i*((l-1)/i); 14 | printf("%lld\n",sum2-sum1); 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Packaging Cupcakes MUFFINS3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | int t; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | unsigned long long int n; scanf("%lld",&n); 10 | printf("%llu\n",n/2+1); 11 | } 12 | } -------------------------------------------------------------------------------- /Palindromic substrings STRPALIN.c: -------------------------------------------------------------------------------- 1 | /*Chef likes strings a lot but he likes palindromic strings more. 2 | Today, Chef has two strings A and B, each consisting of lower case alphabets. 3 | Chef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a substring of A, 4 | s2 is a substring of B such that s1 + s2 is a palindromic string. Here '+' denotes the concatenation between the strings 5 | */ 6 | 7 | #include 8 | #include 9 | int main(void) 10 | { 11 | int t; scanf("%d",&t); 12 | while(t--) 13 | { 14 | char a[1000]={'\0'},b[1000]={'\0'}; 15 | scanf("%s",a); 16 | scanf("%s",b); 17 | int c1[26]={0},c2[26]={0},i,j,flag=0; 18 | for(i=0;i<1000;i++) c1[a[i]-'a']++; 19 | for(i=0;i<1000;i++) c2[b[i]-'a']++; 20 | for(i=0;i<26;i++) 21 | { 22 | if(c1[i]>0 && c2[i]>0) {flag=1; break;} 23 | else flag=0; 24 | } 25 | if(flag==1) printf("Yes\n"); 26 | else printf("No\n"); 27 | } 28 | // your code goes here 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Piece of cake LCH15JAB.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int i,t; scanf("%d",&t); 5 | while(t--) 6 | { 7 | char s[100]; scanf("%s",s); 8 | int c[26]={0},max=0; 9 | if(strlen(s)%2==1) printf("NO\n"); 10 | else 11 | { 12 | for(i=0;i='a' && s[i]<='z') c[s[i]-'a']++; 15 | else if(s[i]>='A' && s[i]<='Z') c[s[i]-'A']++; 16 | } 17 | for(i=0;i<26;i++) 18 | { 19 | if(max 2 | 3 | int main() 4 | { 5 | int t; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | long int n, reverse=0, rem; 10 | scanf("%ld", &n); 11 | while(n!=0) 12 | { 13 | rem=n%10; 14 | reverse=reverse*10+rem; 15 | n/=10; 16 | } 17 | printf("%d\n",reverse); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Simple Multiplication MULTISRM.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define MAX 10000 6 | 7 | char * multiply(char [],char[]); 8 | int main(){ 9 | char a[MAX]; 10 | char b[MAX]; 11 | char *c; 12 | int la,lb,k=0; 13 | int i; 14 | 15 | scanf("%s",a); 16 | scanf("%s",b); 17 | c = multiply(a,b); 18 | if (c[0] == '0') memmove(c, c+1, strlen(c)); 19 | printf("%s\n",c); 20 | return 0; 21 | } 22 | 23 | char * multiply(char a[],char b[]){ 24 | static char mul[MAX]; 25 | char c[MAX]; 26 | char temp[MAX]; 27 | int la,lb; 28 | int i,j,k=0,x=0,y; 29 | long int r=0; 30 | long sum = 0; 31 | la=strlen(a)-1; 32 | lb=strlen(b)-1; 33 | for(i=0;i<=la;i++) 34 | { 35 | a[i] = a[i] - 48; 36 | } 37 | for(i=0;i<=lb;i++) 38 | { 39 | b[i] = b[i] - 48; 40 | } 41 | for(i=lb;i>=0;i--) 42 | { 43 | r=0; 44 | for(j=la;j>=0;j--){ 45 | temp[k++] = (b[i]*a[j] + r)%10; 46 | r = (b[i]*a[j]+r)/10; 47 | } 48 | temp[k++] = r; 49 | x++; 50 | for(y = 0;y=0;i--){ 71 | mul[j++]=c[i] + 48; 72 | } 73 | //if(mul[0]=='0') mul[0]=' '; 74 | mul[j]='\0'; 75 | return mul; 76 | } -------------------------------------------------------------------------------- /Small factorials FCTRL2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,n,a[200],i,j,k,l,m; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | scanf("%d",&n); 10 | m=1; 11 | a[0]=1; 12 | for(j=2;j<=n;j++) 13 | { 14 | l=0; 15 | for(k=0;k=0;i--) 30 | printf("%d",a[i]); 31 | 32 | printf("\n"); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Sum of Digits FLOW006.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int t; 5 | scanf("%d",&t); 6 | while(t--) 7 | { 8 | int n,sum=0; 9 | scanf("%d",&n); 10 | while(n!=0) 11 | { 12 | sum+=n%10; n/=10; 13 | } 14 | printf("%d\n",sum); 15 | } 16 | } -------------------------------------------------------------------------------- /Sum of palindromic numbers SPALNUM.c: -------------------------------------------------------------------------------- 1 | /*A number is called palindromic if its decimal representation is a palindrome. 2 | You are given a range, described by a pair of integers L and R. 3 | Find the sum of all palindromic numbers lying in the range [L, R], inclusive of both the extrema. 4 | */ 5 | 6 | #include 7 | main() 8 | { 9 | int t;scanf("%d",&t); 10 | while(t--) 11 | { 12 | int a,b; scanf("%d %d",&a,&b); 13 | int i; long int s=0; 14 | for(i=a;i<=b;i++) 15 | { 16 | int reverse=0, rem,temp=i; 17 | while(temp!=0) 18 | { 19 | rem=temp%10; 20 | reverse=reverse*10+rem; 21 | temp/=10; 22 | } 23 | if(reverse==i) s+=i; 24 | } 25 | printf("%ld\n",s); 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /The Lead Game TLG.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int t,i,m=0,n=0,d1=0,d2=0,lead1=0,lead2=0,p1,p2; 6 | scanf("%d",&t); 7 | for(i=0;i=n) 13 | { 14 | d1=m-n; 15 | } 16 | if (mlead1) 21 | { 22 | lead1=d1; 23 | } 24 | if (d2>lead2) 25 | { 26 | lead2=d2; 27 | } 28 | } 29 | if (lead1>lead2) 30 | printf ("1 %d",lead1); 31 | if (lead2>lead1) 32 | printf ("2 %d",lead2); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Turbo Sort TSORT.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int arr[1000000]={0}; 4 | 5 | 6 | void main() 7 | { 8 | int a,n; 9 | scanf("%d",&n); 10 | while(n--) 11 | { 12 | scanf("%d",&a); 13 | arr[a]++; 14 | } 15 | a=0; 16 | while(a<1000000) 17 | { 18 | while(arr[a]) 19 | { 20 | printf("%d\n",a); 21 | arr[a]--; 22 | } 23 | a++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /factorial_cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t=0,num=0; 7 | cin>>t; 8 | while(t--){ 9 | long fact =1; 10 | cin>>num; 11 | if(num==0||num==1){ 12 | cout<<1<1){ 15 | for(int i=1;i<=num;i++){ 16 | fact *= i; 17 | } 18 | cout<