C,C++/JAVA/BASH/ASM ARENA

वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है।

QT4 FTP window January 29, 2010

Filed under: C,C++ Programs,QT4 — whoami @ 22:09
Tags: ,

QT4 FTP window executed
/////////install updated qt on feodra
–#yum install qt*

///main.cpp
#include <QtGui/QApplication>
#include <QGridLayout>
#include <QtGui/QWidget>
#include <QLabel>
#include <QPushButton>
#include <QApplication>

    #include "ftpwindow.h"

    int main(int argc, char *argv[])
    {
        Q_INIT_RESOURCE(ftp);

        QApplication app(argc, argv);
        FtpWindow ftpWin;
        ftpWin.show();
        return ftpWin.exec();
    }
/////////////////////////////
//ftpwindow.cpp
#include <QtGui/QApplication>
#include <QGridLayout>
#include <QtGui/QWidget>
#include <QLabel>
#include <QPushButton>
 #include <QtGui>
    #include <QtNetwork>

    #include "ftpwindow.h"

    FtpWindow::FtpWindow(QWidget *parent)
        : QDialog(parent)
    {
        ftpServerLabel = new QLabel(tr("Ftp &server:"));
        ftpServerLineEdit = new QLineEdit("ftp.trolltech.com");
        ftpServerLabel->setBuddy(ftpServerLineEdit);

        statusLabel = new QLabel(tr("Please enter the name of an FTP server."));

        fileList = new QListWidget;

        connectButton = new QPushButton(tr("Connect"));
        connectButton->setDefault(true);

        downloadButton = new QPushButton(tr("Download"));
        downloadButton->setEnabled(false);

        cdToParentButton = new QPushButton;
        cdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png"));
        cdToParentButton->setEnabled(false);

        quitButton = new QPushButton(tr("Quit"));

        ftp = new QFtp(this);

        progressDialog = new QProgressDialog(this);

        connect(ftpServerLineEdit, SIGNAL(textChanged(const QString &)),
                this, SLOT(enableConnectButton()));
        connect(fileList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
                this, SLOT(processItem(QListWidgetItem *)));
        connect(fileList, SIGNAL(itemEntered(QListWidgetItem *)),
                this, SLOT(processItem(QListWidgetItem *)));
        connect(fileList, SIGNAL(itemSelectionChanged()),
                this, SLOT(enableDownloadButton()));
        connect(ftp, SIGNAL(commandFinished(int, bool)),
                this, SLOT(ftpCommandFinished(int, bool)));
        connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
                this, SLOT(addToList(const QUrlInfo &)));
        connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)),
                this, SLOT(updateDataTransferProgress(qint64, qint64)));
        connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
        connect(connectButton, SIGNAL(clicked()), this, SLOT(connectToFtpServer()));
        connect(cdToParentButton, SIGNAL(clicked()), this, SLOT(cdToParent()));
        connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
        connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));

        QHBoxLayout *topLayout = new QHBoxLayout;
        topLayout->addWidget(ftpServerLabel);
        topLayout->addWidget(ftpServerLineEdit);
        topLayout->addWidget(cdToParentButton);

        QHBoxLayout *buttonLayout = new QHBoxLayout;
        buttonLayout->addStretch(1);
        buttonLayout->addWidget(downloadButton);
        buttonLayout->addWidget(connectButton);
        buttonLayout->addWidget(quitButton);

        QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addLayout(topLayout);
        mainLayout->addWidget(fileList);
        mainLayout->addWidget(statusLabel);
        mainLayout->addLayout(buttonLayout);
        setLayout(mainLayout);

        setWindowTitle(tr("FTP"));
    }

    void FtpWindow::connectToFtpServer()
    {
        QApplication::setOverrideCursor(Qt::WaitCursor);
        ftp->connectToHost(ftpServerLineEdit->text());
        ftp->login();
        ftp->list();
        statusLabel->setText(tr("Connecting to FTP server %1...")
                             .arg(ftpServerLineEdit->text()));
    }

    void FtpWindow::downloadFile()
    {
        QString fileName = fileList->currentItem()->text();

        if (QFile::exists(fileName)) {
            QMessageBox::information(this, tr("FTP"),
                                     tr("There already exists a file called %1 in "
                                        "the current directory.")
                                     .arg(fileName));
            return;
        }

        file = new QFile(fileName);
        if (!file->open(QIODevice::WriteOnly)) {
            QMessageBox::information(this, tr("FTP"),
                                     tr("Unable to save the file %1: %2.")
                                     .arg(fileName).arg(file->errorString()));
            delete file;
            return;
        }

        ftp->get(fileList->currentItem()->text(), file);

        progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
        progressDialog->show();
        downloadButton->setEnabled(false);
    }

    void FtpWindow::cancelDownload()
    {
        ftp->abort();
    }

    void FtpWindow::ftpCommandFinished(int, bool error)
    {
        if (ftp->currentCommand() == QFtp::ConnectToHost) {
            if (error) {
                QApplication::restoreOverrideCursor();
                QMessageBox::information(this, tr("FTP"),
                                         tr("Unable to connect to the FTP server "
                                            "at %1. Please check that the host "
                                            "name is correct.")
                                         .arg(ftpServerLineEdit->text()));
                return;
            }

            statusLabel->setText(tr("Logged onto %1.")
                                 .arg(ftpServerLineEdit->text()));
            fileList->setFocus();
            connectButton->setEnabled(false);
            downloadButton->setDefault(true);
            return;
        }

        if (ftp->currentCommand() == QFtp::Get) {
            QApplication::restoreOverrideCursor();
            if (error) {
                statusLabel->setText(tr("Canceled download of %1.")
                                     .arg(file->fileName()));
                file->close();
                file->remove();
            } else {
                statusLabel->setText(tr("Downloaded %1 to current directory.")
                                     .arg(file->fileName()));
                file->close();
            }
            delete file;
            enableDownloadButton();
        } else if (ftp->currentCommand() == QFtp::List) {
            QApplication::restoreOverrideCursor();
            if (isDirectory.isEmpty()) {
                fileList->addItem(tr("<empty>"));
                fileList->setEnabled(false);
            }
        }
    }

    void FtpWindow::addToList(const QUrlInfo &urlInfo)
    {
        QListWidgetItem *item = new QListWidgetItem;
        item->setText(urlInfo.name());
        QPixmap pixmap(urlInfo.isDir() ? ":/images/dir.png" : ":/images/file.png");
        item->setIcon(pixmap);

        isDirectory[urlInfo.name()] = urlInfo.isDir();
        fileList->addItem(item);
        if (!fileList->currentItem()) {
            fileList->setCurrentItem(fileList->item(0));
            fileList->setEnabled(true);
        }
    }

    void FtpWindow::processItem(QListWidgetItem *item)
    {
        QString name = item->text();
        if (isDirectory.value(name)) {
            fileList->clear();
            isDirectory.clear();
            currentPath += "/" + name;
            ftp->cd(name);
            ftp->list();
            cdToParentButton->setEnabled(true);
            QApplication::setOverrideCursor(Qt::WaitCursor);
            return;
        }
    }

    void FtpWindow::cdToParent()
    {
        QApplication::setOverrideCursor(Qt::WaitCursor);
        fileList->clear();
        isDirectory.clear();
        currentPath = currentPath.left(currentPath.lastIndexOf('/'));
        if (currentPath.isEmpty()) {
            cdToParentButton->setEnabled(false);
            ftp->cd("/");
        } else {
            ftp->cd(currentPath);
        }
        ftp->list();
    }

    void FtpWindow::updateDataTransferProgress(qint64 readBytes,
                                               qint64 totalBytes)
    {
        progressDialog->setMaximum(totalBytes);
        progressDialog->setValue(readBytes);
    }

    void FtpWindow::enableConnectButton()
    {
        connectButton->setEnabled(!ftpServerLineEdit->text().isEmpty());
    }

    void FtpWindow::enableDownloadButton()
    {
        QListWidgetItem *current = fileList->currentItem();
        if (current) {
            QString currentFile = current->text();
            downloadButton->setEnabled(!isDirectory.value(currentFile));
        } else {
            downloadButton->setEnabled(false);
        }
    }
////////////////////////////////////////////////////
//ftpwindow.h
#ifndef FTPWINDOW_H
    #define FTPWINDOW_H

    #include <QDialog>
    #include <QHash>

    class QFile;
    class QFtp;
    class QLabel;
    class QLineEdit;
    class QListWidget;
    class QListWidgetItem;
    class QProgressDialog;
    class QPushButton;
    class QUrlInfo;

    class FtpWindow : public QDialog
    {
        Q_OBJECT

    public:
        FtpWindow(QWidget *parent = 0);

    private slots:
        void connectToFtpServer();
        void downloadFile();
        void cancelDownload();

        void ftpCommandFinished(int commandId, bool error);
        void addToList(const QUrlInfo &urlInfo);
        void processItem(QListWidgetItem *item);
        void cdToParent();
        void updateDataTransferProgress(qint64 readBytes,
                                        qint64 totalBytes);
        void enableConnectButton();
        void enableDownloadButton();

    private:
        QLabel *ftpServerLabel;
        QLineEdit *ftpServerLineEdit;
        QLabel *statusLabel;
        QListWidget *fileList;
        QPushButton *quitButton;
        QPushButton *connectButton;
        QPushButton *downloadButton;
        QPushButton *cdToParentButton;
        QProgressDialog *progressDialog;

        QHash<QString, bool> isDirectory;
        QString currentPath;
        QFtp *ftp;
        QFile *file;
    };

    #endif
//////////////////////////////////////////
//ftp.qrc 
///nothing included
/////////////////////////////
//ftpwindow.pro
SOURCES += ftpwindow.cpp \
    main.cpp
HEADERS += ftpwindow.h
RESOURCES += ftp.qrc
QT += network ///if u donot include this line then u ll get error for <QtNetwork>

////////////////






output:-
FTP window

 

QT4 my first program executed January 29, 2010

Filed under: C++ Programs,QT4 — whoami @ 21:35
Tags: ,

QT4 excecuted
after 48 hours of struggle i executed the first program in QT using GUI features
——————————-
its a program to print “hello Qt”

//nn.cpp
#include <QtGui/QApplication>
#include <QGridLayout>
#include <QtGui/QWidget>
#include <QLabel>
#include <QPushButton>
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QLabel *label = new QLabel(" Hello how r u Qt!");
label->show();
QPushButton hello("Hello world!");
hello.resize(100, 30);
hello.show();
return app.exec();
}
////////////////////////////////////
//nn.pro
SOURCES += nn.cpp




ouput:-
Output

 

QT 4 programs January 29, 2010

Filed under: Uncategorized — whoami @ 21:16

AnalogClock
Analog Clock

 

SPOJ 5676. STONE GAME January 29, 2010

Filed under: C,C++ Programs,CODECHEF,Coding,SPOJ — whoami @ 17:21
Tags: , ,

SPOJ 5676. STONE GAME
Problem code: RESN04

–AC–

#include

int main()
{
int T,n,i,j,count;
scanf(“%d”,&T);
while(T–){
scanf(“%d”,&n);
count=0;
for(i=1;i<=n;i++)
{
scanf("%d",&j);
if(i==j) ++count;
}
if(count%2==0) printf("BOB\n");
else printf("ALICE\n");
}

return 0;
}

 

TJU 1748. Power Digit January 27, 2010

Filed under: C,C++ Programs,TJU,TODOLIST — whoami @ 17:14
Tags: , ,

TJU 1748. Power Digit
TODOLIST

Output Limit Exceed

#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;

class A{
   int m,n,i,j,k,rem,res;

  public:
    void input(){
       cin>>m>>n; 
       if(m==0&&n==0) exit(0);
    }

   void calc(){
     rem=m%10;
     switch(rem){
         case 1:
                 res=1;
                 break;
         case 2:
                 i=n%4;if(i==0) i=4;
                 res=pow(2,i);
                 break;
         case 3:
                 i=n%4;if(i==0) i=4;
                 res=pow(3,i);
                 break;
         case 4:
                 i=n%2;if(i==0) i=2;
                 res=pow(4,i);
                 break;
         case 5:
                 res=5;
                 break;
         case 6:
                 res=6;
                 break;
         case 7:
                 i=n%4;if(i==0) i=4;
                 res=pow(7,i);
                 break;
         case 8:
                 i=n%4;if(i==0) i=4;
                 res=pow(8,i);
                 break;
         case 9:
                 i=n%2;if(i==0) i=2;
                 res=pow(9,i);
                 break;
         case 0:
                 res=0;
                 break;
         }
      }

     void output(){
          cout<<(res%10)<<endl;
     }
};

int main()
{
  A obj;
    while(1){
      obj.input();
      obj.calc();
      obj.output();
    }

return 0;
}


 

GTK programming January 27, 2010

Filed under: 29893467,C,C++ Programs,GTK+ — whoami @ 06:26
Tags: ,

GTK(gnu tool kit or gimp tool kit) is object oriented approach in “C”
This is helpful in making projects
Lets try first code in for GTK

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show(window);

  gtk_main();

  return 0;
}




save it as simple.c
compile and run as follows:-
$gcc -Wall -g simple.c -o simple `pkg-config –cflags gtk+-2.0` `pkg-config –libs gtk+-2.0`
$gcc -o simple simple.c `pkg-config –libs –cflags gtk+-2.0`
OR
$gcc $(pkg-config –cflags –libs gtk+-2.0) -o simple simple.c
$./simple

 

TJU 1401. All in All January 26, 2010

Filed under: C,C++ Programs,Cryptography,TJU,ULM LOCAL CONTEST — whoami @ 19:22
Tags: ,

TJU 1401. All in All
—AC—

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
  int i,j,k,flag;
  char s[500000],t[500000];
  while(1)
  {
    if(scanf("%s%s",s,t)==-1) break;
    flag=1;
    j=0;
    for(i=0;i<strlen(s);i++)
    {
      for(;j<strlen(t);)
      {
        if(s[i]==t[j]){j++;break;}
        else{j++;}
        if((j==strlen(t))&&i!=strlen(s))
        {
          flag=0;
          goto down;
        }
          
       }
     }

     down:
      if(flag==1&&i==strlen(s))
         printf("Yes\n");
      else if(flag==0&&i!=strlen(s))
         printf("No\n");
    }

return 0;
}


 

TJU 3013. Alfredo’s Pizza Restaurant January 26, 2010

Filed under: C,C++ Programs,OOPS,TJU,ULM LOCAL CONTEST — whoami @ 18:36
Tags: , ,

TJU 3013. Alfredo’s Pizza Restaurant

–AC–

#include<iostream>
#include<stdlib.h>
#include<math.h>

using namespace std;

class A{
    int r,w,l,i,j;

  public: 
  void input(){
    cin>>r;
    if(r==0) exit(0);
    cin>>w>>l;
    
  }
  void output(){
   if((float)(2*r)>=(float)sqrt(w*w+l*l))
     cout<<" fits on the table.\n";
   else
     cout<<" does not fit on the table.\n";
   }
};

int main(){
  A obj;
  int i=0;
  while(1){
   obj.input();
   cout<<"Pizza "<<++i;
   obj.output();
  }

return 0;
}


 

SPOJ 5201. Stacks of Bricks January 26, 2010

Filed under: C,C++ Programs,SPOJ — whoami @ 18:12
Tags: ,

SPOJ 5201. Stacks of Bricks

–AC–

#include<iostream>
using namespace std;

class A{
   int n,a[1000],i,j,k,s;

  public:
     void input(){
      cin>>n;
      s=0;
     for(i=0;i<n;i++){
       cin>>a[i];
       s+=a[i];
      }
     }

    void calc(){
     j=s/n;
     k=0;
     for(i=0;i<n;i++)
     {
       if(a[i]>j)
       k=k+a[i]-j;
     }
    }
   void output(){
     cout<<k<<endl;
   }
};

int main()
{
  A obj;
  obj.input();
  obj.calc();
  obj.output();

return 0;
}



 

TJU 1138. Binomial Showdown January 26, 2010

TJU 1138. Binomial Showdown
--AC–

#include<iostream>
#include<stdlib.h>

using namespace std;

class A{
   long long int i,j,k,N,K,tmp;
  public:
    void input(){
         cin>>N>>K;
         
         if(N==0&&K==0) exit(0);
    }
    void calc(){
       i=N-K;
       if(N==K||K==0) {tmp=1;}
       else if(K==1){tmp=N;}
       else  if(i>K)
       {
          j=1;
          tmp=1;
          
          while(j<=K)
          {
            if(N%j==0)
            tmp=tmp*(N/j);
            else if(tmp%j==0)
             tmp=N*(tmp/j);
            else tmp=(N*tmp)/j;
             
            j++;
            N--;
         
          }
        }
        else if(i<=K)
        {       
           j=1;
           tmp=1;
          while(j<=i)
          {
            if(N%j==0)
            tmp=tmp*(N/j);
            else if(tmp%j==0)
            tmp=N*(tmp/j);
            else tmp=(N*tmp)/j;
            j++;
            N--;
           }
         }
       }
      void output(){
         cout<<tmp<<endl;
      }
};

int main()
{
  A a;
 
  while(1){
    a.input();
    a.calc();
    a.output();
  }

return 0;
}


 

RAM model of computation January 26, 2010

Filed under: Algo & Data Structure — whoami @ 12:10
Tags:

RAM (here Random Access Machine) model of compuation is an abstract model in which we try to analyze the working of our ALGORITHMS . Thought this model is different from real computers, it is helpful in many way.

LINK

 

Compile Linux kernel fedora 11 January 26, 2010

Filed under: fedora,LINUX — whoami @ 09:10
Tags: , ,

steps:-

[1] download kernel from kernel.org
now u have linux-2.6.X.tar.gz or linux-2.6.X.tar.bz2 in home folder
[3]$tar tar zxvf linux-2.6.x.tar.gz
[4]$cd linux-2.6.x
[5]$make defconfig
it will take less than 5 minutes
note**- if u use defconfig, it will take very less around 30 minutes to complete the whole process.

but i issued $make oldconfig, and the whole compilation and making modules took around 2.30 hrs.

u can use and experiment with:
$make xconfig
[6]$make bzImage
this will take around 20 minutes
[7]$make modules
if u used defconfig, then it may take 1 or 2 minutes.
But i used oldconfig, and it tool 1.20 hrs to make modules
COMPILATION AND MODULES COMPILING IS COMPLETE NOW

[8]$make modules_install
This step may deny permission
so make entry in root mode mode
$su -
password
$cd /home/username
$cd linux-2.6.x
$make modules_install

same thing happened as i discussed in step 7
[9]$ mkinitrd /boot/initrd-2.6.x.img 2.6.x
[10] $ cp arch/i386/boot/bzImage /boot/bzImage-KERNEL_VERSION
$ cp System.map /boot/System.map-KERNEL_VERSION
$ ln -s /boot/System.map-KERNEL_VERSION /boot/System.map
follow this link
[11]$cp cp .config /boot/config-2.6.x
[12]cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.29
[13]now edit grub.conf
$gedit /boot/grub/menu.lst
edit it as written in link
my grub.conf is below after editing, though its not booting
———————————–
my grub.conf
——————————-
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,8)
# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=20
splashimage=(hd0,8)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.30.9-96.fc11.i686.PAE)
root (hd0,8)
kernel /vmlinuz-2.6.30.9-96.fc11.i686.PAE ro root=/dev/mapper/VolGroup-lv_root rhgb quiet
initrd /initrd-2.6.30.9-96.fc11.i686.PAE.img
title Fedora (2.6.30.9-90.fc11.i686.PAE)
root (hd0,8)
kernel /vmlinuz-2.6.30.9-90.fc11.i686.PAE ro root=/dev/mapper/VolGroup-lv_root rhgb quiet
initrd /initrd-2.6.30.9-90.fc11.i686.PAE.img
title Fedora (2.6.30.8-64.fc11.i686.PAE)
root (hd0,8)
kernel /vmlinuz-2.6.30.8-64.fc11.i686.PAE ro root=/dev/mapper/VolGroup-lv_root rhgb quiet
initrd /initrd-2.6.30.8-64.fc11.i686.PAE.img
title Test Kernel (2.6.29)
root (hd0,8)
kernel /vmlinuz-2.6.29 ro root=/dev/mapper/VolGroup-lv_root rhgb quiet
initrd /boot/initrd-2.6.29.img

title Xp
rootnoverify (hd0,0)
chainloader +1
===================================
Though this kernel is not booting, i will try to fix it soon

Thanks
njoooy linuxxxxxxxxx

 

TJU 2498. Uncle Jack January 20, 2010

Filed under: C,C++ Programs,Coding,PKU,TJU,TODOLIST,WA — whoami @ 20:41
Tags: , , ,

TJU 2498. Uncle Jack
TODOLIST
WRONG ANSWER
{big multiplication based question}

#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;

class A{
   long long i,j,N,D,R;
    
   public:
       void input(){
         cin>>N>>D;
         if(N==0&&D==0) exit(0);
       }
       void output(){
        R=powf(N,D);
        cout<<R<<endl;
       }
};

int main()
{
 A a;
 while(1){
   a.input();
   a.output();
 }

return 0;
}

 

Linux logging problems &Solutions January 20, 2010

Filed under: fedora,LINUX — whoami @ 20:13
Tags: , ,

[1]Get access of root by:
adding a line to kernel line- write “single” then press “enter” to save and then press “b” to boot.
follow
U will directly enter into command line as root . Now u can change the root password by:
$passwd

[2]Now suppose u forgot the passwords of users Or in some version of linux U cannot graphically boot as root. Then u can do following things:-

**Add new users and their password** for this :
root#adduser -m username -ppass
root#passwd username
follow this link

***to graphically boot for root*** do as:-
#vi /etc/pam.d/gdm
and comment “#” one line
follow this link

 

C++ Struct uses January 20, 2010

Filed under: C++ Programs — whoami @ 18:10
Tags: ,

link

 

 
Follow

Get every new post delivered to your Inbox.