Wednesday, January 22, 2020

Codeforces 131A cAPS lOCK Solution in C

  1. #include <stdio.h>
  2. int main()
  3. {
  4. char ch[106];
  5. int i,j,ck=1;
  6. scanf("%s",ch);
  7. for(i=1;ch[i]!='\0';i++)
  8. {
  9. if(ch[i]>=97&&ch[i]<=122)
  10. {
  11. ck=0;
  12. break;
  13. }
  14. }
  15. if(ck==1)
  16. {
  17. if(ch[0]>=65&&ch[0]<=90)
  18. ch[0]=ch[0]+32;
  19. else
  20. ch[0]=ch[0]-32;
  21. for(j=1;ch[j]!='\0';j++)
  22. {
  23. ch[j]=ch[j]+32;
  24. }
  25. }
  26. printf("%s\n",ch);
  27. return 0;
  28. }

Tuesday, January 21, 2020

Codeforces 133A HQ9+ Solution in C

  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. int i,n,p=0;
  6. char s[120];
  7. scanf("%s",s);
  8. n=strlen(s);
  9. for (i=0;i<n;i++)
  10. {
  11. if (s[i]=='H' || s[i]=='Q' || s[i]=='9')
  12. {
  13. p++;break;
  14. }
  15. }
  16. if (p>0) printf("YES\n");
  17. else printf("NO\n");
  18. return 0;
  19. }

Codeforces 160A Twins Solution in C

  1. /// OmShantihari
  2. /// Author: Sujan Mridha
  3. /// CSE 5th batch, University of Barishal
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. int main ()
  8. {
  9. int i,n,m,b,c,s,a[200];
  10. cin>>n;
  11. for (i=0,s=0;i<n;i++)
  12. {
  13. cin>>a[i];
  14. s+=a[i];
  15. }
  16. sort (a,a+n);
  17. s/=2;
  18. for (i=n-1,c=0,b=0;i>=0;b++,i--)
  19. {
  20. c+=a[i];
  21. if (c>s) break;
  22. }
  23. cout<<++b<<endl;
  24. return 0;
  25. }

Codeforces 158B Taxi Solution in C++


  1. #include <iostream >
  2. using namespace std;
  3. int main()
  4. {
  5. int n,m,g1=0,g2=0,g3=0,s=0;
  6. cin>>n;
  7. for (int i=0;i<n;i++)
  8. {
  9. cin>>m;
  10. if (m==4) s++;
  11. else if (m==3) g3++;
  12. else if (m==2) g2++;
  13. else g1++;
  14. }
  15. g1-=g3;
  16. s+=g3;
  17. if (g2%2==0 && g2>0)
  18. {
  19. s+=g2/2;
  20. g2=0;
  21. }
  22. else if (g2%2==1 && g2>0)
  23. {
  24. s+=g2/2+1;
  25. g1-=2;
  26. }
  27. if (g1>0)
  28. {
  29. s+=g1/4;
  30. if (g1%4>0) s++;
  31. }
  32. cout<<s<<endl;
  33. return 0;
  34. }

Codeforces 546A Soldier and Bananas Solution in C

  1. #include<stdio.h>
  2. int main()
  3. {
  4. int i,a,c;
  5. long int b,x=0;
  6. scanf("%d%ld%d",&a,&b,&c);
  7. for (i=1;i<=c;i++)
  8. {
  9. x=x+i*a;
  10. }
  11. if (x>b) printf("%ld\n",x-b);
  12. else printf("0\n");
  13. return 0;
  14. }

Codeforces 116A Tram Solution in C++



  1. ///SMS
  2. #include <iostream>
  3. using namespace std;
  4. int main ()
  5. {
  6. int i,j,a,b,x=0,y=0,n,s=0;
  7. cin>>n;
  8. for (i=0;i<n;i++)
  9. {
  10. cin>>a>>b;
  11. x-=a;
  12. x+=b;
  13. if (x>s) s=x;
  14. }
  15. cout<<s<<endl;
  16. return 0;
  17. }

Codeforces 122A Lucky Division Solution in C


  1. ///SHS
  2. #include <iostream>
  3. using namespace std;
  4. int main ()
  5. {
  6. int i,j,k,a[]={4,7,44,47,77,444,447,477,777};
  7. cin>>k;
  8. for (i=0;i<9;i++)
  9. {
  10. if (k%a[i]==0)
  11. {
  12. cout<<"YES"<<endl;
  13. return 0;
  14. }
  15. }
  16. cout<<"NO"<<endl;
  17. return 0;
  18. }

Codeforces 58A Chat room Solution in C



  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. int i,n,l=0;
  6. char a[120];
  7. scanf("%s",a);
  8. n=strlen(a);
  9. for (i=0;i<n;i++)
  10. {
  11. if (a[i]=='h' && l==0) l++;
  12. else if (a[i]=='e' && l==1) l++;
  13. else if (a[i]=='l' && l==2) l++;
  14. else if (a[i]=='l' && l==3) l++;
  15. else if (a[i]=='o' && l==4) l++;
  16. if (l==5) break;
  17. }
  18. if (l==5) printf("YES\n");
  19. else printf("NO\n");
  20. return 0;
  21. }

Codeforces 69A Young Physicist Solution in C



  1. #include<stdio.h>
  2. int main()
  3. {
  4. int o,n,a,b,c,s,t,u;
  5. s=0;
  6. t=0;
  7. u=0;
  8. scanf("%d",&n);
  9. for (o=0; o<n; o++)
  10. {
  11. scanf("%d %d %d",&a,&b,&c);
  12. s=s+a;
  13. t=t+b;
  14. u=u+c;
  15. }
  16. if (s==0 && t==0 && u==0) printf("YES\n");
  17. else printf("NO\n");
  18. return 0;
  19. }

Codeforces 236A Boy or Girl Solution in C++


  1. ///SHS
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5. int main ()
  6. {
  7. int i,n,m=0,x[124]={0};
  8. char s[200];
  9. cin>>s;
  10. n= strlen (s);
  11. for (i=0;i<n;i++) x[s[i]]++;
  12. for (i=0;i<124;i++) if (x[i]>0) m++;
  13. if (m%2==1) cout<<"IGNORE HIM!";
  14. else cout<<"CHAT WITH HER!";
  15. return 0;
  16. }

Codeforces 266A Stones on the Table Solution in C

  1. #include <iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5. int n,s=0;
  6. string m;
  7. cin>>n>>m;
  8. if (n==1)
  9. {
  10. cout<<"0"<<endl;
  11. return 0;
  12. }
  13. for (int i=0;i<n-1;i++)
  14. {
  15. if (m[i]==m[i+1]) s++;
  16. }
  17. cout<<s<<endl;
  18. return 0;
  19. }

Codeforces 263A Beautiful Matrix Solution in C



  1. #include<stdio.h>
  2. int main()
  3. {
  4. int mat[5][5], i , j, l, count = 0 , m, n;
  5.  
  6. for(i = 0; i < 5; i++){
  7. for(j = 0; j < 5; j++){
  8. scanf("%d", &mat[i][j]);
  9. }
  10. }
  11.  
  12. for(i = 0; i < 5; i++){
  13. for(j = 0; j < 5 ; j++){
  14. if(mat[i][j] == 1){
  15. m = i;
  16. n = j;
  17. break;
  18. }
  19. }
  20. }
  21. for( l = 0; l < 5; l++){
  22. if( n > 2){
  23. n = n - 1;
  24. count++;
  25. }
  26. else if (n == 2){
  27. break;
  28. }
  29. else if( n < 2){
  30. n = n + 1;
  31. count++;
  32. }
  33. }
  34.  
  35. for( l = 0; l < 5; l++){
  36. if( m > 2){
  37. m = m - 1;
  38. count++;
  39. }
  40. else if (m == 2){
  41. break;
  42. }
  43. else if( m < 2){
  44. m = m + 1;
  45. count++;
  46. }
  47. }
  48.  
  49. printf("%d\n", count);
  50.  
  51. return 0;
  52. }
  53.  
  54.  

Codeforces 281A Word Capitalization Solution in C



  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. char n[3500];
  6. scanf("%s",&n);
  7. if (n[0]>='a' && n[0]<='z') n[0]=n[0]-32;
  8. printf("%s\n",n);
  9. return 0;
  10. }

Codeforces 131A cAPS lOCK Solution in C

#include <stdio.h> int main () { char ch [ 106 ]; int i , j , ck = 1 ; scanf ( "%s" , ch ); ...