Sunday, May 14, 2017

uva online judge 11461

UVa online judge 543

UVA online judge 543

Goldbach's conjecture

Link:
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=484 


Solution:

#include<bits/stdc++.h>
using namespace std;
#define N 1000000
int primes[N];
void Sieve()
{
    int i;
    for(i=2; i<=N; i++)
        primes[i] = 1;
    primes[0] = primes[1] = 0;

    int len = sqrt(N);
    for(i = 2; i <= len; ++i)
    {
        if(primes[i])
        {
            for( int k = i * i; k <= N; k += i )
                primes[k] = 0;
        }
    }
    primes[2] = 0;
}
int main()
{

    Sieve();

    int n,b,a;
    while(scanf("%d", &n)&&n)
    {
        for( a = 3; a < n; ++a)
        {
            if( primes[a] )
            {
                b = n - a;
                if( primes[b] )
                {
                    // printf("%d = %d + %d\n", n, a, b);
                    cout <<n<<" "<<"="<<" "<<a<<" "<<"+"<<" "<<b<<endl;
                    break;
                }
            }
        }
        if(a+b!=n)
            // printf("Goldbach's conjecture is wrong\n");
            cout <<"Goldbach's conjecture is wrong"<< endl;
    }
    return 0;
}

Friday, May 12, 2017

UVa online judge 11876 N+NOD(N)

 UVA online judge

problem:11876

N+ NOD (N)

problem link(PDF):

https://uva.onlinejudge.org/external/118/11876.pdf

 

 SOLUTION:

#include<bits/stdc++.h>
using namespace std;
bool prime[1000009];
vector<int>num;
vector<int>pr;
int binary(int a)
{
    int mid,L=0,u=num.size()-1;
    while(L<=u)
    {
        mid=(u+L)/2;
        if(a>num[mid])
            L=mid+1;
        else if(a<num[mid])
            u=mid-1;
        else return mid;
    }
   return mid;
}

Sunday, May 07, 2017

Solution to Uva problem 11530 - SMS Typing


Problem link:: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2525 



soliution :: 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    map< char,int >mp;
    int n,ans;
    string s;
    mp['a']=1,mp['b']=2,mp['c']=3,mp['d']=1,mp['e']=2,mp['f']=3,mp['g']=1,mp['h']=2,mp['i']=3,mp['j']=1,mp['k']=2,mp['l']=3,mp['m']=1;
    mp['n']=2,mp['o']=3,mp['p']=1,mp['q']=2,mp['r']=3,mp['s']=4,mp['t']=1,mp['u']=2,mp['v']=3,mp['w']=1,mp['x']=2,mp['y']=3,mp['z']=4;
    mp[' ']=1,mp['\n']=0;
    cin>>n;
    getchar();
    for(int i=0;i<n;i++)
    {
        ans=0;
        getline(cin,s);
        for(int i=0;i<s.size();i++)
        {
            ans=ans+mp[s[i]];
        }
        cout<<"Case #"<<i+1<<": "<<ans<<endl;
    }
    return 0;

}
/*this problem solution is solved with mapping if you don't know mapping then you will fail to undrstand so stay with us to know about mapping */
/* if you don't know about cin && cout put scanf instead of cin && printf instead of cout. Both works the same. */

Saturday, April 29, 2017

UVA ONLINE JUDGE 488

UVA online JUDGE 

PROBLEM:488

(TRIANGLE WAVE)

PROBLEM LINK:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=429

  1.  

    Solution:

      #include<bits/stdc++.h>  using namespace std; int main()

    {

UVA ONLINE JUDGE PROBLEM 11636

UVA ONLINE JUDGE  

PROBLEM 11636

Hello World!
 
Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n,j;

Friday, April 28, 2017

C Programming Course - 01


How to print?


Today we will learn how to print a program in C language. At first of the code , we have to write a header file. 

#include<stdio.h>

    here 'stdio' means 'Standers Input and Output. And ' .h ' says that it is a header file.
After that, we've to write,

int main()

     that means , from here the main program is going to be started. Then just write a second bracket and there write your program. 

UVA ONLINE JUDGE (PROBLEM: 11577)

UVA ONLINE JUDGE

(PROBLEM: 11577)



Solution::

#include<bits/stdc++.h>
using namespace std;
int
freq[30],t;
int main()
{