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

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