Monday, October 1, 2018

UVa problem solution reverse and add -10018

Discuss: in this problem just simply reverse the digit using very naive process that is also fine. and then whether it is palindrome or not if it is not palindrome then repeat the process for newly create number. you will get your answer,
there is no tricky part  in this problem.

try yourself, before see the code


Saturday, September 29, 2018

UVa problem solution 10523 - Very Easy !!!

problem link:

Discuss: there is many approach to solve this problem. i using java language since it has BigInteger class. if you know java and function of BigInteger then it's very naive problem to you. don't forget to name your class Main(capital M) this is for UVa.

try yourself, before see the code


UVa problem solution 623 - 500!

Problem link:

Discuss: you can solve the problem in many way. but java is naive one. if you know about java BigInteger function and how it works. then just find factorial using any loop. but one thing to cite in uva you must have Class type as Main(M is in capital letter). and there is no tricky part in this problem.


try yourself, before see the code



Friday, September 28, 2018

UVa problem soultion 725 - Division

problem link:

Discuss: this is just simple implementation problem. just simply check every digit using while loop you will get the output.

try yourself, before see the code


Wednesday, September 19, 2018

UVa problem solution 455 - Periodic Strings

problem link:


Discuss: in this problem you can find out longest common sub string using KMP. then trying divide length of string by(length-longest sub) if it's divide than longest sub will be result otherwise there is no result but n.

try yourself, before see the code.

Saturday, September 15, 2018

10298 - Power Strings


10298 - Power Strings

Discuss: this is simple string matching problem. in this problem you have asked to how many reputation you need to make the string. for that i do is create a longest common sequence array. which suffix and also prefix of the string. and if n-l divide n then it can form with this sub string. and the reputation is need n/(n-l). just simple do it.

try yourself,before see the code


Friday, September 14, 2018

10679 - I Love Strings!!

10679 - I Love Strings!!

Discuss: In this problem just simply use KMP pattern searching algorithm. and you will get the result. there  is no tricky part in this problem.
try yourself, before see the code


Thursday, April 12, 2018

UVa problem solution 10931 - Parity

problem link:


Discuss: in this problem you just simply convert decimal to binary. then count the number of one's in binary that will be the 'P'. and for converting you can use c++ built in STL     string binary = std::bitset<31>(n).to_string();   . and there is no tricky part in this problem.

try yourself, before see the code



Friday, April 6, 2018

UVa problem solution 514 - Rails

problem link:

Discuss: in this problem train come from direction A in increasing order and there can many permutation to go direction B. input gives you the permutation to go direction.you can easily check it by using stack.just if top element of stack is less then ith element then push more. if ith element is in stack but not in top then the permutation is impossible



Thursday, April 5, 2018

UVa problem 673 - Parentheses Balance

problem link:

Discuss: This problem i want to solve by counting parentheses before  i know stack. since i know i just laugh at myself. if you know stack then it is just implementation problem for you.there no tricky part in this problem

try yourself before see the code


UVa problem solution 727 - Equation

problem link:

Discuss: in this problem you may first trouble with taking input.it's quite okay it's a terrific one before but it's not like that. you can take input as string and if the first character of string is null character just break the loop.and obviously give a null end of your main string. and other simply need to convert it infix to post fix. if you know stack then it just  a implementation problem for you.

try your self, before see the code



Friday, March 9, 2018

UVa problem solution 10954 - Add All

problem link:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin >>n&&n)
    {
         int i,j,cnt=0,flag=0,a,b,x,sum=0;
        priority_queue<int>que;
        for(i=0;i<n;i++)
        {
            cin >>j;
            j*=-1;
            que.push(j);
        }
        while(que.size()!=1)
        {
            a=que.top();
            que.pop();
            b=que.top();
            que.pop();
            x=(a+b);
            sum+=(x*-1);
            que.push(x);
            if(que.size()==1)
                break;
        }

       cout <<sum<<endl;
    }
    return 0;
}

Wednesday, February 28, 2018

UVa problem solution 11503 - Virtual Friends

problem link:

Discuss: you can solve this problem by simply using disjoint set. just rank the set. and print for every new element. and there is no tricky part. you can use map for using  number instead of string.

try yourself, before see the code



UVa problem solution 10685 - Nature

problem link:

Discuss: you can simply solve this problem using disjoint set. just rank the set by counting the number of element in the set. and you can also use map for using number instead of string. and there is no tricky part in this problem.

try yourself before see the code



UVa problem 459 - Graph Connectivity


problem link:

Discuss: you can solve this problem in many ways like dfs,bfs, disjoint set. i used here disjoint set.just simply put the array element in vector and then erase every duplicate element for in similar set only number exist in vector. the i just count the number of element in the vector. there is also a case where no connectivity among nodes. if use scanf for scan newline than on that case it will not give you any output. so where any problem if need to scan a line only than use getchar() instead of scanf. and there is no more tricky part in this problem.


try your self, before see the code



Saturday, February 24, 2018

UVa problem solution 10608 - Friends

problem link:

Discuss: this is simple disjoint set problem. to solve this problem just use a extra array to store how much element add in a set. for that in make in makeUnion function when you check is the parent to node equal or not.then if not equal then you set ara[x]=y similar way we just count the member of the set also.such m[y]+=m[x] and just print the biggest element of the m array.there is no tricky part in this problem


Saturday, January 27, 2018

UVa problem soultion 1112 - Mice and Maze

problem link:

Discuss: in this problem you can simply use dijksta and solve it.  jut loop through 1 to n and call dijkstra every time.if distant of exit node is less or equal then timer then make count increase. there is no tricky part in this problem.


try yourself , before see the code


Friday, January 26, 2018

UVa problem solution 10986 - Sending email

problem link:

Discuss: in this problem you can simply use dijksta algorithm.if you know the algorithm then this problem just direct implementation of that algroithm. there is no tricky part in this problem

try yourself, before see the code


UVa problem solution 10305 - Ordering Tasks

problem link:

Discuss: you can solve this problem using modified dfs or bfs. we call dfs for every adjacent vertices first.then push every vertex to stack. then just print stack.there is no tricky part in this problem.

try yourself, before see the code