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

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