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

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

Sieve of Eratosthenes March 21, 2010

Filed under: C,C++ Programs — whoami @ 05:55
Tags: ,

SPOJ 2. Prime Generator.
Code works for smaller inputs

//sieve of Erastosthenes
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
vector<int> prime;

void sieve(int n)
{
  for(int i=0;i<=n;i++)
    prime.push_back(1);
 
  prime[0]=0;
  prime[1]=0;

  int m=sqrt(n);

  for(int i=2;i<=m;i++)
   if(prime[i])
     for(int k=i*i;k<=n;k=k+i)
       prime[k]=0;  

}
int main()
{
  
  sieve(1000);

  int cases;
  scanf("%d",&cases);
  while(cases--){
  int m,n;
  scanf("%d%d",&m,&n);
  for(int i=max(2,m);i<=n;i++){
   if(prime[i])
    printf("%d\n",i);
   }
  if(cases!=0)
  printf("\n");
  }

return 0;
}

Advertisements
 

TLE -Chain Quine March 20, 2010

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

Chain Quine
My partial solution:

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

int main()
{
  int cases,logn,n;
  scanf("%d",&cases);
  while(cases--){
    scanf("%d",&n);
    if(n>0){
    logn=log2(n);
    if(n==1) printf("2\n");
    else
    if((int)pow(2,logn)==n)
        printf("%d\n",(int)pow(2,logn));
    else
    printf("%d\n",(int)pow(2,logn+1));
    }
    else{
printf("#include<stdio.h>\n");
  printf("#include<stdlib.h>\n");
printf("#include<string.h>");printf("\n#include<math.h>\n");printf(" int main(){int cases,logn,n; scanf(");printf("%c",34);printf("%%d");printf("%c",34);printf(",&cases);");printf("while(cases--){");printf("scanf(");printf("%c",34);printf("%%d");printf("%c",34);printf(",&n);");printf("if(n>0){logn=log2(n);if((int)pow(2,logn)==n)");printf("printf(");printf("%c",34);printf("%%d\\n");printf("%c",34);
printf(",n);");printf("else printf(");printf("%c",34);printf("%%d\\n");printf("%c",34); printf(",(int)pow(2,logn));}");printf("""}return 0;}");


}

}

return 0;
}

 

Codeforces Beta Round #5

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

B. Center Alignment

–AC–

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

int main()
{
  char s[2000][2000];
  int i,j,k,l,m,n,max,p,tmp=0;
  i=1;
  while(1){
  if(!gets(s[i])) break;
  ++i;
  }
  max=0;
  for(j=1;j<=i;j++){
    l=strlen(s[j]);
    if(l>max)
     max=l;
  }

  tmp=1;
  for(j=0;j<=max+1;j++)
   
   
    printf("*");
  printf("\n");
  for(j=1;j<i;j++){
     printf("*");
     l=strlen(s[j]);
     m=max-l;
     n=m/2;
     p=n;
     if(m%2!=0){
       tmp++;
       if(tmp%2==0){
           n=n;
           p=n+m%2;
       }    
       else{
        p=n;
        n=n+m%2;
       
        }
      }
    for(k=0;k<n;k++)
     printf(" ");
     printf("%s",s[j]);
    for(k=0;k<p;k++)
     printf(" ");
     printf("*\n");
   }

   for(j=0;j<=max+1;j++)
    printf("*");
   printf("\n");

return 0;
}
  

 

Codeforces Beta Round #5

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

A. Chat Server’s Outgoing Traffic
–AC–

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

int main()
{
  char s1[1000],s2[1000];
  int i,j,k,l,m,n,count;
  int total;
   count=0;
   total=0;
  while(1){
   if(!gets(s1)) break;
  
   if(s1[0]=='+') ++count;
   else if(s1[0]=='-') --count;
   else {l=0;
         for(i=0;s1[i]!=':';i++);
         for(i=i+1;s1[i]!='\0';i++)
           ++l;
         total=total+l*count;
        }
   }

  printf("%d\n",total);

return 0;
}
   

 

kill any process Forcibly in Unix March 18, 2010

Filed under: fedora,LINUX,Top Coder,TOPCODER — whoami @ 19:18
Tags: , , ,

Often it happens that some programs hangs and it doesnot close by clicking the “X ” button.In that case we can use “$kill ” command to kill the process.”$Kill” has several options attached with it. To kill something forcibly we use “-9” option. I show u some example.
——————
step1:->
$ps -a
-> this will list all process (but not that which runs in the background)
$ps -e
->this will list all process , evem those that runs in the background

—————————————
step2->
Now that we have listed the process by above two methods, chose the “pid” of that process which u want to kill
$kill “pidnumber”
->where pidnumber is the one u noted from above which u want to stop.
**this may not kill some process. So for this use -9 option
$kill -9 “pidnumber”
-> now ur required process will be closed
———————————–
Actually sometimes while using TopCoder Arena, the applet didnot closes or it Hangs, To stop it either i has to restart the system or i had to log off and then log in. Now through theses commnads with -9 option i can close it.
sample:->

[abc@localhost ~]$ ps 
  PID TTY          TIME CMD
 3564 pts/0    00:00:00 bash
 3857 pts/0    00:00:00 ps
[abc@localhost ~]$ ps -a
  PID TTY          TIME CMD
 3858 pts/0    00:00:00 ps
[abc@localhost ~]$ ps -e
  PID TTY          TIME CMD
    1 ?        00:00:00 init
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 migration/0
    4 ?        00:00:00 ksoftirqd/0
    5 ?        00:00:00 watchdog/0
    6 ?        00:00:00 migration/1
    7 ?        00:00:00 ksoftirqd/1
    8 ?        00:00:00 watchdog/1
    9 ?        00:00:01 events/0
   10 ?        00:00:00 events/1
   11 ?        00:00:00 cpuset
   12 ?        00:00:00 khelper
   13 ?        00:00:00 netns
   14 ?        00:00:00 async/mgr
   15 ?        00:00:00 kintegrityd/0
   16 ?        00:00:00 kintegrityd/1
   17 ?        00:00:00 kblockd/0
   18 ?        00:00:00 kblockd/1
   19 ?        00:00:00 kacpid
   20 ?        00:00:00 kacpi_notify
   21 ?        00:00:00 ata/0
   22 ?        00:00:00 ata/1
   23 ?        00:00:00 ata_aux
   24 ?        00:00:00 ksuspend_usbd
   25 ?        00:00:00 khubd
   26 ?        00:00:00 kseriod
   27 ?        00:00:00 khungtaskd
   28 ?        00:00:00 pdflush
   29 ?        00:00:00 pdflush
   30 ?        00:00:00 kswapd0
   31 ?        00:00:00 aio/0
   32 ?        00:00:00 aio/1
   33 ?        00:00:00 crypto/0
   34 ?        00:00:00 crypto/1
   40 ?        00:00:00 scsi_eh_0
   41 ?        00:00:00 scsi_eh_1
   43 ?        00:00:00 kpsmoused
   44 ?        00:00:00 kstriped
   45 ?        00:00:00 ksnapd
   46 ?        00:00:00 usbhid_resumer
   69 ?        00:00:00 kdmflush
   70 ?        00:00:00 kdmflush
   71 ?        00:00:00 kjournald2
   80 ?        00:00:00 kauditd
  158 ?        00:00:00 udevd
  776 ?        00:00:00 kmmcd
  795 ?        00:00:00 tifm
  863 ?        00:01:23 phy0
  894 ?        00:00:00 pccardd
  989 ?        00:00:00 hd-audio0
 1063 ?        00:00:00 kmpathd/0
 1064 ?        00:00:00 kmpathd/1
 1065 ?        00:00:00 kmpath_handlerd
1093 ?        00:00:00 kjournald
 1179 ?        00:00:00 kondemand/0
 1180 ?        00:00:00 kondemand/1
 1212 ?        00:00:00 auditd
 1214 ?        00:00:00 audispd
 1215 ?        00:00:00 sedispatch
 1239 ?        00:00:00 rsyslogd
 1262 ?        00:00:00 rpcbind
 1281 ?        00:00:03 dbus-daemon
 1291 ?        00:00:00 avahi-daemon
 1292 ?        00:00:00 avahi-daemon
 1301 ?        00:00:00 cupsd
 1322 ?        00:00:00 acpid
 1330 ?        00:00:01 hald
 1333 ?        00:00:00 console-kit-dae
 1334 ?        00:00:00 hald-runner
 1424 ?        00:00:04 hald-addon-inpu
 1442 ?        00:00:00 hald-addon-gene
 1458 ?        00:00:00 hald-addon-cpuf
 1459 ?        00:00:00 hald-addon-acpi
 1475 ?        00:00:00 pcscd
 1489 ?        00:00:00 NetworkManager
 1495 ?        00:00:00 nm-system-setti
 1499 ?        00:00:00 wpa_supplicant
 1507 ?        00:00:00 rpc.statd
 1533 ?        00:00:00 rpciod/0
 1536 ?        00:00:00 rpciod/1
 1543 ?        00:00:00 rpc.idmapd
 1551 ?        00:00:00 bluetoothd
 1565 ?        00:00:00 bluetooth
 1578 ?        00:00:00 sshd
 1618 ?        00:00:00 gpm
 1629 ?        00:00:00 crond
 1640 ?        00:00:00 atd
 1648 ?        00:00:00 gdm-binary
 1649 tty4     00:00:00 mingetty
 1650 tty5     00:00:00 mingetty
 1651 tty2     00:00:00 mingetty
 1652 tty3     00:00:00 mingetty
 1653 tty6     00:00:00 mingetty
 1694 ?        00:00:00 gdm-simple-slav
 1695 tty1     00:05:29 Xorg
 1724 ?        00:00:00 dbus-launch
 1772 ?        00:00:00 sendmail
 1773 ?        00:00:00 sendmail
 1840 ?        00:00:01 devkit-power-da
 1842 ?        00:00:00 devkit-daemon
 1895 ?        00:00:00 gdm-session-wor
 1920 ?        00:00:00 gnome-keyring-d
 1934 ?        00:00:00 gnome-session
 1949 ?        00:00:00 dbus-launch
 1951 ?        00:00:00 dbus-daemon
 2032 ?        00:00:02 gconfd-2
 2037 ?        00:00:00 gnome-settings-
 2050 ?        00:00:04 metacity
 2055 ?        00:00:24 pulseaudio
 2056 ?        00:00:02 gnome-panel
 2059 ?        00:00:00 gconf-helper
 2061 ?        00:00:00 gvfsd
 2073 ?        00:00:00 gvfs-fuse-daemo
 2077 ?        00:00:02 nautilus
 2079 ?        00:00:00 bonobo-activati
 2084 ?        00:00:00 seapplet
 2085 ?        00:00:00 nm-applet
 2086 ?        00:00:00 bluetooth-apple
 2090 ?        00:00:00 python
 2091 ?        00:00:00 notification-da
 2093 ?        00:00:00 gnome-volume-co
 2096 ?        00:00:00 im-settings-dae
 2098 ?        00:00:00 kerneloops-appl
 2105 ?        00:00:01 gpk-update-icon
 2116 ?        00:00:01 gnome-power-man
 2129 ?        00:00:02 kerneloops
 2314 ?        00:00:00 gconf-im-settin
 2348 ?        00:00:00 gvfsd-trash
 2351 ?        00:00:00 gvfs-gdu-volume
 2353 ?        00:00:01 devkit-disks-da
 2354 ?        00:00:00 devkit-disks-da
 2364 ?        00:00:00 trashapplet
 2365 ?        00:00:03 wnck-applet
 2368 ?        00:00:00 gvfs-gphoto2-vo
 2373 ?        00:00:01 clock-applet
 2377 ?        00:00:01 tomboy
 2378 ?        00:00:00 notification-ar
 2380 ?        00:00:00 gdm-user-switch
 2388 ?        00:00:00 gvfsd-burn
 2398 ?        00:00:00 run-mozilla.sh
 2413 ?        00:04:51 firefox
 2432 ?        00:00:01 gnome-screensav
 2753 ?        00:00:02 gedit
 3562 ?        00:00:00 gnome-terminal
 3563 ?        00:00:00 gnome-pty-helpe
 3564 pts/0    00:00:00 bash
 3718 ?        00:00:01 javaws -&gt;this is TopCoder application running
 3763 ?        00:00:18 javaws-&gt;--do--
 3860 pts/0    00:00:00 ps
[abc@localhost ~]$ kill -9 3718
[abc@localhost ~]$ kill -9 3763
[abc@localhost ~]$ kill -9 2413
[abc@localhost ~]$ ps -e


 

Edit .qrc file in Qt March 5, 2010

Filed under: C++ Programs,QT4 — whoami @ 07:00
Tags: , ,

In the begining it may not be easy to create qrc file in QT4 as its not to do it .

U can do it by adding the several through the window options . Read this article
Be sure to add the files in current directory.

 

Execute .jar file on Double Click -Linux March 2, 2010

Filed under: JAVA,LINUX,Top Coder — whoami @ 09:08
Tags: , ,

Read this link.

Actually u have to change 2 things- in properties of .jar file-
1. set the permission to run it as a program
2.then open with – use custom command , there find the location of jexec and press open.
Now ur file directly open with this jexec command after pressing double click…..
I am using it run The Editors for TopCoder
Thanks