রবিবার, ২০ মার্চ, ২০১৬

lightOj 1227 - Boiled Eggs solve by c++

#include<iostream>
using namespace std;

int main()
{
    int T, n, p, q, c = 0, i, w, t, arry[50];
    cin >> T;
    while(T--)
    {
        w = 0;
        t = 0;
        cin >> n >> p >> q;
        for(i = 0; i < n; i++)
            cin >> arry[i];
        for(i = 0; i < n; i++)
        {
            if(w + arry[i] <= q && t+1 <= p)
            {
                w += arry[i];
                t++;
            }
        }
         cout << "Case " << ++c << ": " <<  t << endl;
    }
    return 0;
}


ahmed shuvo969
আহমেদ শুভ৯৬৯

মঙ্গলবার, ১৫ মার্চ, ২০১৬

lightOj 1249 - Chocolate Thief solve by c++

#include<iostream>
#include<string.h>
using namespace std;

int main()
{
  int a, b, c, test, k, n,l, v, max, min, i;
   char str[21], s1[21],s2[21];
   cin >> test;
   for(i = 1; i <= test; i++)
   {   cin >> n;
       cin >> str >> a >> b >> c;
       max = min = a * b * c;
       for(k = 1; k < n; k++)
       {
           cin >> str >> a >> b >> c;
           v = a * b * c;
          if (v > max) {
            strcpy (s1 , str);
            max = v;
         }
         else if (v < min) {
            strcpy (s2 , str);
            min = v;
         }
       }
       if(max == min) cout << "Case " << ": " << i << "no thief" << endl;
       else cout << "Case " << ": " << i << s1 << " took chocolate from " << s2 << endl;
   }
    return 0;
}



ahmed shuvo969
আহমেদ শুভ৯৬৯

সোমবার, ৭ মার্চ, ২০১৬

Compare is tow string is same? solve by c++

#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str1 ("green apple");
  string str2 ("red apple");
  cin >> str1 >> str2;

  if (str1.compare(str2) != 0)
    cout << "No" << endl;
   else
    cout << "Yes" << endl;
  return 0;
}

শুক্রবার, ৪ মার্চ, ২০১৬

lightOj 1354 - IP Checking solve by c++

#include<iostream>
using namespace std;

int DiToBi(int n)
{
    int mul = 1, result = 0;
    while(n > 0)
    {
        result += n % 2 * mul;
        mul *= 10;
        n /= 2;
    }
    return result;
}
int main()
{
    int T, da, db, dc, dd, ba, bb, bc, bd, cas = 0;
    char cha;
    cin >> T;
    while(T--)
    {
        cin >> da >> cha >> db >> cha >> dc >> cha >> dd;
        cin >> ba >> cha >> bb >> cha >> bc >> cha >> bd;
        if( DiToBi(da) == ba && DiToBi(db) == bb && DiToBi(dc) == bc && DiToBi(dd) == bd)
             cout << "Case " << ++cas << ": " << "Yes" << endl;
        else
             cout << "Case " << ++cas << ": " << "No" << endl;
    }
    return 0;
}






ahmed shuvo969
আহমেদ শুভ৯৬৯

বৃহস্পতিবার, ৩ মার্চ, ২০১৬

lightOj 1387 - Setu solve by c++

#include<iostream>
using namespace std;

int main()
{
    int tCase, nCase, t = 0, n, m, sum ;
    string s;
    cin >> tCase;
    while(tCase--)
    {
       cin >> n;
       sum = 0;
       cout << "Case "  << ++t << ":" << endl;
       while(n--)
       {
           cin >> s;
           if(s == "donate")
            {
                cin >> m;
                sum += m;
            }
           if(s == "report")
            cout << sum << endl;
       }
    }
    return 0;
}

ahmed shuvo969
আহমেদ শুভ৯৬৯

মঙ্গলবার, ২৩ ফেব্রুয়ারী, ২০১৬

lightOJ 1414 - February 29

#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
map<string,int> mp;
char mon[20][25]={"January",
 "February", "March", "April",
  "May", "June", "July", "August",
   "September", "October", "November",
   "December"};
int main()
{

    for(int i=0;i<12;i++)
    mp[mon[i]]=i+1;
    int cas,T=1;
    cin >> cas;
    int y,m,t1,t2;char a[25];
    while(cas--)
    {
        scanf("%s%d,%d",a,&m,&y);
        t1=t2=0;
        if((y%400==0)||(y%100!=0&&y%4==0))
        {
            if(mp[a]>2)
            y++;
        }y--;
        t1+=(y/4-y/100+y/400);
        scanf("%s%d,%d",a,&m,&y);
        if((y%400==0)||(y%100!=0&&y%4==0))
        {
            if(mp[a]>2||(mp[a]==2&&m==29))
            y++;
        }y--;
        t2+=(y/4-y/100+y/400);
        printf("Case %d: %d\n",T++,t2-t1);
    }
    return 0;
}


ahmed shuvou969
আহমেদ শুভ ৯৬৯

বৃহস্পতিবার, ১৮ ফেব্রুয়ারী, ২০১৬

lightOj 1113 - Discover the Web solve by c++

#include<iostream>
#include<stdio.h>
#define S 103
using namespace std;

string Browser[S];

int main(){
    int t, last, ind, cs = 0;
    string inp;
    cin >> t;
    while(t--){
        last = 0, ind = 0;
        Browser[last] = "http://www.lightoj.com/";
        cout << "Case " << ++cs << ":" << endl;
        while(cin >> inp){
            if(inp == "QUIT")break;
            else if(inp == "VISIT"){
                cin >> inp;
                cout << inp << endl;
                Browser[++ind] = inp;
                last = ind;
            }
            else if(inp == "FORWARD"){
                if(ind + 1 > last)puts("Ignored");
                else cout << Browser[++ind] << endl;
            }
            else if(inp == "BACK"){
                if(ind - 1 < 0)puts("Ignored");
                else cout << Browser[--ind] << endl;
            }
        }
    }
    return 0;
}


ahmed shuvo969
আহমেদ শুভ৯৬৯

বুধবার, ১৭ ফেব্রুয়ারী, ২০১৬

lightOj 1042 - Secret Origins solve by c++

#include<iostream>
using namespace std;

int main()
{
    long int n, t, i, j;
    cin >> t;
    for(i = 1; i <= t; i++)
    {
        cin >> n;
        j = n;
        while(j++)
        {
            if(__builtin_popcount(n) != __builtin_popcount(j))
            {
              continue;
            }
            else
              cout << "Case " << i << ": " << j << endl;
              break;
        }
    }

    return 0;
}

ahmed shuvo969

মঙ্গলবার, ১৬ ফেব্রুয়ারী, ২০১৬

lightOj 1001 - Opposite Task solve by c ++

#include<iostream>
using namespace std;

int main()
{
   int a, b, n, t;
   cin >> t;
   while(t--)
   {
       cin >> n;
       a = n / 2;
       b = n - a;
       cout << a << " " << b << endl;
   }
    return 0;
}


ahmed shuvo969
আহমেদ শুভ৯৬৯ 

বৃহস্পতিবার, ১১ ফেব্রুয়ারী, ২০১৬

lightOj 1045 - Digits of Factorial solve by c++

#include<iostream>
#include<math.h>
using namespace std;
int test,p;
long i,n,b;
double f[1000010];

int main()
{
    cin >> test;
    for(i = 1; i <= 1000000; i++)
        f[i] = log((i)) + f[i-1];
    for(p = 1; p <= test; p++)
    {
        cin >> n >> b;
        cout << "Case " << p << ": " << (long)(f[n]/(f[b]-f[b-1])+1) << endl;;
    }
    return 0;
}

print number of same char of two string solve by c++

#include<iostream>
using namespace std;

int main()
{
    int n, ln = 0;
    char str[12], com[12];
    cin >> str >> com;

    for(int i = 0; str[i] != '\0'; i++)
    {
        for(int j = 0; com[j] != '\0'; j++)
        {
            if(str[i] == com[j])
                ln ++;
        }
    }
    cout << ln << endl;
    return 0;
}


Compare two string equal or not solve by c++

#include<iostream>
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    if(a == b)
        cout << "yes" << endl;
    else
        cout << "Not" << endl;
    return 0;
}



রবিবার, ৭ ফেব্রুয়ারী, ২০১৬

Print the total binary one(1) of a number solve by c++

#include<iostream>
using namespace std;

int main()
{
    int n;
    cout << "Enter the number: ";
    cin >> n;
    cout << __builtin_popcount(n) << endl;
    return 0;
}


ahemd shuvo969

lightOj 1182 - Parity solve by c++

#include <iostream>
using namespace std;
int main()
 {
    int TC,tc,n;
    tc = 1;
    cin >> TC;
    while(tc<=TC) {
        cin >> n;
        if(__builtin_popcount(n)%2==0)
            cout << "Case " << tc << ": "  << "even" << endl;
        else
            cout << "Case " << tc << ": " << "odd" << endl;
           tc++;
    }
    return 0;

 }


ahmed shuvo969

Check palindrome solve by c++

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str, a;
    cout << "Enter a string: ";
    cin >> str;
    a = str;
    reverse((str.begin()), (str.end()));
    if(a == str)
        cout << "Palindrome" << endl;
    else
        cout << "Not palindrome" << endl;
    return 0;
}


ahmed shuvo969

Reverse a string solve by c++

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string str;
    cout << "Enter a string: ";
    cin >> str;
    reverse((str.begin()), (str.end()));
    cout << str << endl;
    return 0;
}


ahmed shuvo969

শনিবার, ৬ ফেব্রুয়ারী, ২০১৬

reverse string by c++

#include<iostream>
using namespace std;

int main()
{
    char ch[10][100];
    int i, n;
    cout << "Enter number how many  string you revers: ";
    cin >> n;
    for(i = 0; i < n; i++)
    {
        cin >> ch[i];
    }
     for(i = n- 1; i >= 0; i--)
            cout << ch[i] << endl;

    return 0;
}


ahmed shuvo969

check a string weather is palindrome or not by c++

#include<iostream>
using namespace std;

int main( )
{
    char str[80];
    cout<<"Enter string: ";
    cin.getline(str, 80);

    int l;
    for(l = 0; str[l] != '\0'; l++);
    int i;
    for(i = 0; (i < l/2) && (str[i] == str[l - i - 1]); i++);

    if(i == l/2)
        cout << "Palindrome";
    else
        cout << "Not a palindrome";

    return 0;
}

/// ahmed shuvo969

lightOj 1136 - Division by 3 solve by c++

#include<iostream>
using namespace std;
typedef unsigned int ll;
ll calc(ll k)
{
return (k / 3) * 2 + (k % 3 == 2 ? 1 : 0);
}
int main()
{
int t, cas = 0;
ll a, b;
cin >> t;
while (t--)
{
cin >> a >> b;
cout << "Case " << ++cas << ": "  << (calc(b) - calc(a - 1)) << endl;
}
return 0;
}


ahmed shuvo969

শুক্রবার, ৫ ফেব্রুয়ারী, ২০১৬

lightOj 1107 - How Cow solve by c++

#include <iostream>
using namespace std;

int main()
{
   int T,t,m,x,y,x1,x2,y1,y2,i;
    cin>>T;
    t=1;
    while(t <= T) {
        cout << "Case " << t << ":" <<endl;
        cin >> x1 >> y1 >> x2 >> y2;
        cin >> m;
        for(i = 0; i < m; i++) {
            cin >> x >> y;
            if(x > x1 && x < x2 && y > y1 && y < y2)
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
       }
       t++;
   }
   return 0;
}

ahmed shuvo969

lightOj 1072 - Calm Down solve by c++

#include<iostream>
#include<iomanip>
#include<math.h>
#define pi 2.0*acos(0.0)


 using namespace std ;
 int main ()
 {
     int t , i  ;
     cin>>t ;
     for (i=1 ; i<=t ; i++)
     {
         double x , n , R ,r ;
         cin >> R >> n;
         x=sin(pi / n);
         r=(x * R) / (1 + x) ;
         cout << setprecision(10) << "Case " << i << ": " << r <<endl ;
     }
     return 0 ;
 }


///ahmed shuvo969

Print closer integer of a double solve by c++

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    double n;
    cout << "Enter the number : " ;
    cin >> n;
    double t = n - (int)n;
    if(t >= .5)
        cout << ceil(n) << endl;
    else
        cout << floor(n) << endl;

    return 0;
}


///ahmed shuvo969

URI - 1005 solve by c++

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
   float A, B, MEDIA;
    cin >> A >> B;
     MEDIA =((A*3.5)+(B*7.5))/(3.5+7.5);

    cout << fixed << setprecision(5) <<  "MEDIA = " <<  MEDIA << endl;

    return 0;
}

///ahmed shuvo969

বৃহস্পতিবার, ৪ ফেব্রুয়ারী, ২০১৬

check an input integer or double by c++

#include<iostream>
using namespace std;

int main()
{
    double a;
    cout << "Enter the number: ";
    cin >> a;
    int b = (int)a;
    if((a / b) == 1)
        cout << "Integer" << endl;
    else
        cout << "Double" << endl;
    return 0;
}

///ahmed shuvo969



বুধবার, ৩ ফেব্রুয়ারী, ২০১৬

Get the lenght of number/character without using header file by c++

#include<iostream>
using namespace std;

int main()
{
    int i = 0,  degit = 0;
    char string[80];
    cout << "enter the number/character : ";
    cin >> string;
    while((string[i++]) != '\0')
            ++degit;
    cout << "The length of string is : " << degit << endl;

   return 0;
}





///ahmed shuvo969

Get the lenght of number/character by c++

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string n;
    cout << "Enter the number/character : ";
    cin >> n;
    cout <<"The length of this number: "<< n.length() << endl;
    return 0;
}

///ahmed shuvo969

lightOj 1294 - Positive Negative Sign solve by c++

#include <iostream>
using namespace std;

int main(){

    int T;
    cin >> T;
    for(int t = 1; t <= T; t++){
        long long int n,m;
        cin >> n >> m;
        cout << "Case " << t << ": " << (n*m)/2 << endl;
    }
    return 0;
}

///ahmed shuvo969

Convert Decimal to Binary by c++

#include <iostream>
using namespace std;
int main()
{
    long dec,rem,i=1,sum=0;
    cout<<"Enter the decimal to be converted:";
    cin>>dec;
    while(dec>0)
    {
        rem=dec%2;
        sum=sum + (i*rem);
        dec=dec/2;
        i=i*10;
    };
    cout<<"The binary of the given number is:"<<sum<<endl;

    return 0;
}


//ahmed shuvo969

Convert Binary to Decimal by c++

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    int outcome = 0, i, n;
    cout << "Enter the binary number: ";
    cin >> n;
    for(i = 0; n > 0; i++)
    {
        if(n % 10 == 1)
            outcome += pow(2, i);
        n = n / 10;
    }
    cout << "The decimal number of " << n << " is : " << outcome << endl;
    return 0;
}

//ahemdshuvo969

মঙ্গলবার, ২ ফেব্রুয়ারী, ২০১৬

lightOj-1311 - Unlucky Bird solve by c++

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
int test;
double v1, v2, v3, a1, a2, t, t1, t2, fly, s;
cin >> test;

for(int i = 1; i <= test; i++)
{
    cin >> v1 >> v2 >> v3 >> a1 >> a2;
    t1 = v1 / a1;
    t2 = v2 / a2;
    t = max(t1, t2);
    fly = v3 * t;
    s = v1 * t1 + 0.5 * -a1 * t1 * t1;
    s += v2 * t2 + 0.5 * -a2 * t2 * t2;
    cout << fixed << setprecision(9) << "Case " << test << ": " << s << " " << fly << endl;
}
    return 0;
}

ahmed shuvo969

মঙ্গলবার, ১২ জানুয়ারী, ২০১৬

               solve lightOJ 1305 - Area of a Parallelogram  in c++






#include<iostream>
#include<math.h>
using namespace std;

int main()

{
    int ax, ay, bx, by, cx, cy, dx, dy, t, s;
    cin >> t;
    for(int i =1; i <= t; i++)
    {
       cin >> ax >> ay >> bx >> by >> cx >> cy;
       dx = ax + cx - bx;
       dy = ay + cy - by;
       s = fabs((ax * by + bx * cy + cx * ay) - (bx * ay + cx * by + ax * cy));

       cout << "Case " << i << ": " << dx  << " "  << dy << " " << s << endl;

    }
    return 0;
}

____ahmed shuvo 969

           solve lightOj 1331 - Agent J in c++



#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
#define PI acos(-1)
int main()
{
    int t, i;
    double res, tri_area, r1, r2, r3, a, b, c, angle_a, angle_b, angle_c, area_r1, area_r2, area_r3, s;
    cin >> t;
    for(i = 1; i <= t; i++)
    {
        cin >> r1 >> r2 >> r3;
        a = r1 + r2;
        b = r1 + r3;
        c = r2 + r3;
        angle_a = acos((b*b + c*c - a*a) / (2 * b * c)) * 180.0/PI;
        angle_b = acos((a*a + c*c - b*b) / (2 * a * c)) * 180.0/PI;
        angle_c = acos((b*b + a*a - c*c) / (2 * b * a)) * 180.0/PI;
        area_r1 = 0.5 * (r1 * r1) * (angle_c * (PI/180.0));
        area_r2 = 0.5 * (r2 * r2) * (angle_b * (PI/180.0));
        area_r3 = 0.5 * (r3 * r3) * (angle_a * (PI/180.0));
        s = (a + b + c) / 2.0;
        tri_area = sqrt(s * (s - a) * (s - b) * (s - c));
        res = tri_area - (area_r1 + area_r2 + area_r3);
        cout << "Case " << i << ": " << fixed << setprecision(10) << res << endl;
    }
    return 0;
}


ahmed shuvo 969

                                   

solve  in c++




#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int t, test;
    double ox, oy, ax, ay, bx, by, a, b, o, angle_o, min_dis;
    cin >> test;
    for(t = 1; t <= test; t++)
    {
        cin >> ox >> oy >> ax >> ay >> bx >> by;
        b = sqrt((ox - ax) * (ox - ax) + (oy - ay) * (oy - ay));
        a = sqrt((ox - bx) * (ox - bx) + (oy - by) * (oy - by));
        o = sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay));
        angle_o = acos((b*b + a*a - o*o)/(2 * b * a));
        min_dis = a * angle_o;
        cout << "Case " << t << ": " << fixed << setprecision(8) << min_dis << endl;
    }
    return 0;
}



___ahmed shuvo 969

সোমবার, ১১ জানুয়ারী, ২০১৬

               solve Fibonacci series in c++



 #include<iostream>
using namespace std;

int main()

{
    int first = 0, second = 1, next, n;
    cout << "Enter the term number: ";
    cin >> n;
    for(int i = 0; i <= n; i++)
    {
        if( i <= 1)
            next = i;
        else
        {
            next = first + second;
            first = second;
            second = next;
        }
        cout << next << " ";
    }

    return 0;

}


///ahmed shuvo 969

শনিবার, ৯ জানুয়ারী, ২০১৬


LIGHT OJ NO: 1053



#include<iostream>
#include<math.h>
using namespace std;

int main()
{
   long int T, a, b, c, l, s, m;
    double d;
    cin >> T;
   for(int i = 1; i <= T; i++)
    {
        cin >> a >> b >> c;
        if( a> b && a > c)
            {
            l = a;
            m = b;
            s = c;
            }
        else if ( b > a && b > c)
           {
            l = b;
            m = a;
            s = c;
           }
        else
        {
            l = c;
            m = b;
            s = a;
        }
        d = acos((s * s + m * m - l * l)/ 2 * s * m) * ( 180 / acos(-1));
        if(d == 90)
            cout << "Case " << i << ": " << "yes" << endl;
        else
            cout << "Case " << i << ": " << "no" << endl;
   }

    return 0;
}



___ahmed shuvo 969

শুক্রবার, ৮ জানুয়ারী, ২০১৬

              solve lightOj 1000 in c++


#include<iostream>
using namespace std;

int main()
{
    int a, b, t;
    cin>> t;
    for(int i = 1; i <= t; i++)
    {
        cin >> a >> b;
        cout << "Case " << i << ": " << a + b << endl;
    }

    return 0;
}

_____ahmede shuvo 969
solve lightOj 1015 - Brush (I) in c++


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    long long int tst,t,num,tp,sum,i;
    cin>>tst;
    for(t=1;t<=tst;t++)
    {
        sum=0;
        cin>>num;
        for(i=0;i<num;i++)
        {
            cin>>tp;
            if(tp>0)
            {
                sum=sum+tp;
            }
        }
        cout<<"Case "<<t<<": "<<sum<<endl;
    }
    return 0;
}


///ahmed shuvo 969