Sunday, February 28, 2016

Drawing Flag of Bangladesh with Java

import java.awt.*;
import java.applet.*;

public class BanFlag extends Applet
{

public void paint (Graphics g)
{
 g.setColor(Color.black);
 g.fillRect(10,30,20,500);
 g.setColor(new Color(46, 139, 89));
 g.fillRect(40,50,300,170);
 g.setColor(Color.red);
 g.fillOval(120,80,120,120);
}

}

Tuesday, February 23, 2016

Round 1 Contest ( Test Version)

It is a simple problem volume and useful for beginner. Everyone can solve the tasks easily. Have fun and keep coding. Thank you.   Click here to enter the Round 1 Contest

Monday, February 22, 2016

UVA 10696 f91

#include<iostream>

using namespace std;
int main()
{  int n;
    while(cin>>n)
    {
    if(n==0) break;
    else if(n>=101) cout<<"f91("<<n<<") = "<<n-10<<endl;
    else if(n<=100) cout<<"f91("<<n<<") = 91"<<endl;
}
    return 0;
}

UVA 575 Skew Binary

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;

int main()
{
string num;
long long len,i;
long long sum=0;
long long j;
j=1;

while(cin>>num)
{
if(num=="0") break;
len=num.length();

for(i=len-1; i>=0; i--)
{
if(num[i]=='1') sum=sum + (pow(2,j)-1);
else if(num[i]=='2') sum= sum+  (2 * (pow(2,j)-1));
j++;
}
cout<<sum<<endl;
sum=0;
j=1;


}
}

Sunday, February 21, 2016

URI 1015 - Distance Between Two Points

#include<stdio.h>
#include<math.h>

int main()
{
    float x1,y1,x2,y2,p1,p2,res;
    scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
    p1=x2-x1;
    p2=y2-y1;
    res=sqrt((p1*p1)+(p2*p2));
    printf("%.4f\n",res);
    return 0;
}

URI 1589 - Bob Conduit

#include <stdio.h>

int main() {

   int R1, R2, tc;
   scanf("%d",&tc);
   while(tc--){
       scanf("%d %d", &R1, &R2);
       printf("%d\n",R1 + R2);
   }

    return 0;
}

URI 1078 - Multiplication Table

#include <stdio.h>

int main() {

    int i,N;
    scanf("%d",&N);
    for(i=1; i<=10; i++){
        printf("%d x %d = %d\n",i,N,i * N);
    }
    return 0;
}

URI 1074 - Even or Odd

#include <stdio.h>

int main() {

   int i,n;
   int b;
   scanf("%d",&n);
   for(i=1; i<=n; i++){
       scanf("%d",&b);
       if(b%2==0 && b>0)printf("EVEN POSITIVE\n");
       if(b%2==0 && b<0)printf("EVEN NEGATIVE\n");
       if(b%2!=0 && b>0)printf("ODD POSITIVE\n");
       if(b%2!=0 && b<0)printf("ODD NEGATIVE\n");
       if(b==0)printf("NULL\n");
   }

    return 0;
}

URI 1073 - Even Square

#include <stdio.h>

int main() {

   int i,n;
   scanf("%d",&n);
   for(i=2; i<=n; i=i+2){
       printf("%d^2 = %d\n",i,i*i);
   }

    return 0;
}

URI 1067 - Odd Numbers

#include <stdio.h>

int main() {

   int i,n;
   scanf("%d",&n);
   for(i=1; i<=n; i=i+2){
       printf("%d\n",i);
   }

    return 0;
}

URI 1065 - Even Between five Numbers

#include <stdio.h>

int main() {

   int i, sum=0;
  int n;
   for(i=1; i<=5; i++){
    scanf("%d",&n);
     
       if(n%2==0){
           sum+=1;
       }
   }
      printf("%d valores pares\n",sum);

    return 0;
}

Friday, February 19, 2016

UVA 11417 GCD

#include<bits/stdc++.h>

using namespace std;

int main()
{
int i,j;
int n,g;
g=0;

while(cin>>n)
{
if(n==0) break;


for(i=1; i<n; i++)
{
for(j=i+1;j<=n; j++)
{
g+= __gcd(i,j);
}

}
cout<<g<<endl;

g=0;


}
return 0;
}

UVA 382 Perfection

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{

long long n,i,j,sum;
sum=0;
cout<<"PERFECTION OUTPUT"<<endl;
while(cin>>n)
{
if(n==0) break;


if(n==1){
cout<<setw(5)<<n<<"  "<<"DEFICIENT"<<endl;
}
else{
for(i=2; i<n-1; i++)
{
if(n%i==0) sum+=i;
}

if(sum+1==n) cout<<setw(5)<<n<<"  "<<"PERFECT"<<endl;
else if(sum+1>n) cout<<setw(5)<<n<<"  "<<"ABUNDANT"<<endl;
else if(sum+1<n) cout<<setw(5)<<n<<"  "<<"DEFICIENT"<<endl;
}
sum =0;

}
cout<<"END OF OUTPUT"<<endl;


return 0;
}

Wednesday, February 17, 2016

UVA 10038 Jolly Jumper

    #include<bits/stdc++.h> #include<cstdlib> using namespace std; int main() { int a[3000],b[3000],i,c,n; while(cin>>n) { c=1; for(i=0; i<n; i++) { cin>>a[i]; } for(i=0; i<n-1; i++) { b[i]=abs(a[i+1]-a[i]); } sort(b,b+i); for(i=1; i<n; i++) { if(b[i]==b[i-1]) { c=0; break; } } if(c==0) cout<<"Not jolly"<<endl; else cout<<"Jolly"<<endl; } }

UVA 100 3n+1 Problem

    #include<iostream>
    #include<cmath>

    using namespace std;

    int main()
    {
    int i,j;
    while(cin>>i)
    {
    cin>>j;
    int ti = i;
    int tj = j;
    if(i>j) swap(i,j);

    int mc,mxc;
    mxc =0;

    while(i<=j)
    {
    mc=1;
    unsigned int n = i;

    while(n!=1)
    {
    if(n%2==1) n = 3 *n +1;
    else n = n/2;
    mc++;
    }
    if(mc>mxc)
    {
    mxc = mc;
    }
    i++;
    }
    cout<<ti<<" "<<tj<<" "<<mxc<<endl;
    }
    return 0;
    }

Sunday, February 14, 2016

Digital Clock Applet - Java

import java.applet.Applet;
import java.awt.Graphics;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class clock extends Applet implements Runnable{
Thread t,t1;

public void start(){

t = new Thread(this);
t.start();
}

public void run(){
t1= Thread.currentThread();

while(t1==t){

repaint();
try{

t1.sleep(1000);

}

catch(InterruptedException e){
}

}
}
public void paint(Graphics g){

Calendar cal = new GregorianCalendar();
String hour = String.valueOf(cal.get(Calendar.HOUR));
String min = String.valueOf(cal.get(Calendar.MINUTE));
String sec = String.valueOf(cal.get(Calendar.SECOND));

g.drawString(hour+" : "+min+" : "+sec,20,30);
}

}

For running applet create a file name clock.html and edit it like below and Run applet

<APPLET CODE="clock.class" HEIGHT ="400" WIDTH = "400"></APPLET>

Saturday, February 13, 2016

UVA 12279 Emoogle Balance

#include<iostream>

using namespace std;

int main()
{
int t,i,n;
int c,c1,m;
c=0; c1=0;
m=1;

while(cin>>t)
{

if(t==0) break;

for(i=0; i<t; i++)
{
cin>>n;
if(n==0) c1+=1;
if(n>=1 && n<=99) c+=1;
}
cout<<"Case "<<m<<": "<<(c-c1)<<endl;

c=0; c1=0;
m++;
}
}

Merit List Generator Program Coded in C++

#include<iostream>

using namespace std;

int main()
{
int st;
cout<<"Enter student number :"<<endl;


cin>>st;
int a[st],b[st],i,j,temp;
string name[st];

for(i=0; i<st; i++)
{

cout<<"Enter student nick name and marks separated by space:\t";
cin>>name[i];
cin>>a[i];

b[i]=a[i];
}

cout<<"\n\nYour result sheet is below :\n";
cout<<"---------------------------\n"<<endl;

for(i=0; i<st-1; i++)
{
for(j=0 ; j<st-i-1; j++)
{
if(a[j]<a[j+1])
{
temp= a[j];
a[j]=a[j+1];
a[j+1] = temp;

}
}
}

for(i=0; i<st; i++)
{
cout<<"Roll "<<i+1<<": ";
for(j=0; j<st; j++)
{
if(a[i] == b[j])
{
cout<<name[j]<<"\t";
cout<<a[i]<<endl;
}
}
}
}

Friday, February 12, 2016

UVA 374 Big Mod

#include<iostream>
#include<cmath>

using namespace std;


int big_mod(int base, int power, int mod)
{
    if(power==0)    return 1;
    else if(power%2==1)
    {
        int p1 = base % mod;
        int p2 = (big_mod(base,power-1,mod))%mod;
        return (p1*p2)%mod;
    }
    else if(power%2==0)
    {
        int p1 = (big_mod(base,power/2,mod))%mod;
        return (p1*p1)%mod;
    }
}

int main()
{
int b,p,m;

while(cin>>b)
{
cin>>p>>m;
int bb;
bb = big_mod(b,p,m);
cout<<bb<<endl;
}

return 0;
}

Monday, February 8, 2016

STL: Vector example, a simple program

#include<vector>
#include<bits/stdc++.h>

using namespace std;

int main()
{
string s[10];
vector<string> name;         //you can use your own data type
vector<string>::iterator i;

for(int j=0; j<10; j++)
{
getline(cin,s[j]);
if(s[j]=="#") break;
name.push_back(s[j]);
}
for(i=name.begin(); i!=name.end(); ++i)
{
cout<<*i<<endl;
}
}

STL: Set example, a simple program

#include<set>
#include<bits/stdc++.h>

using namespace std;

int main()
{
string s[50];
set<string>myset;
set<string>::iterator i;


int k;
for(k=0; k<50; k++)
{
getline(cin,s[k]);
if(s[k]=="#") break;
}

for(int i =0 ;i<50; i++)
{
myset.insert(s[i]);
}

for(i=myset.begin(); i!=myset.end(); ++i)
{
cout<<*i<<endl;
}

return 0;
}

Friday, February 5, 2016

UVA 12592 - Slogan Learning of Princess

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cstdio>
#include<cctype>
#include<cmath>


using namespace std;

int main()
{
    string s[200],p[100],r;
    int n,k,q;
    while(cin>>n)
    {
       getchar();
        for(int i=0;i<n;i++)
        {
            getline(cin,s[i]);
            getline(cin,p[i]);
        }
        cin>>q;
       getchar();
        while(q--)
        {
            getline(cin,r);
            for(int i=0;i<n;i++)
            {
                if(s[i]==r)
                {
                    cout<<p[i]<<endl;
                    break;
                }
            }
        }
    }
 return 0;
}

UVA 11799 - Horror Dash

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#define x s[j]

using namespace std;

int main()
{
long long i,j,n,max,l;
long long s[1000];
max=0;

cin>>n;

for(i=0; i<n; i++)
{
cin>>l;
for(j=0; j<l; j++){
cin>>s[j];
if(s[j]>max){
max=s[j];
}
}
cout<<"Case "<<i+1<<": "<<max<<endl;
max=0;
}

return 0;
}

Tuesday, February 2, 2016

Adding two number via dialog box in Java

import javax.swing.JOptionPane;

public class javaAdd{

public static void main(String args[]){

String a,b;

a = JOptionPane.showInputDialog("Enter first number:");
b = JOptionPane.showInputDialog("Enter second number:");

int sum=  Integer.parseInt(a) + Integer.parseInt(b);

JOptionPane.showMessageDialog(null,"Sum is "+sum,"Result",JOptionPane.PLAIN_MESSAGE);

}

}