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 131A cAPS lOCK Solution in C

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