Pages

Thursday, October 22, 2009

UVA Problem#11530


Question:
http://uva.onlinejudge.org/external/115/11530.html

Solution:
int main(){
.....
..... 

if(s[j]=='a' || s[j]=='d' || s[j]=='g' || s[j]=='j' || s[j]=='m' 
|| s[j]=='p' || s[j]=='t' || s[j]=='w' || s[j]==' '){
c += 1;
}else if(s[j]=='b' || s[j]=='e' || s[j]=='h' || s[j]=='k' 
|| s[j]=='n' || s[j]=='q' || s[j]=='u' || s[j]=='x'){
c += 2;
}else if(s[j]=='c' || s[j]=='f' || s[j]=='i' || s[j]=='l' || 
s[j]=='o' || s[j]=='r' || s[j]=='v' || s[j]=='y'){
c += 3;
}else{
c += 4;
}
....
.... 
 
}


UVA Problem#10222

Question:

Solutions :
#include<stdio.h>
#include<string.h>

void pri(char c){
if(c == ']'){
printf("p");
}else if(c == '['){
printf("o");
}else if(c == 'p' || c == 'P'){
printf("i");
}else if(c == 'o' || c == 'O'){
printf("u");
}else if(c == 'i' || c == 'I'){
printf("y");
}else if(c == 'u' || c == 'U'){
printf("t");
}else if(c == 'y' || c == 'Y'){
printf("r");
}else if(c == 't' || c == 'T'){
printf("e");
}else if(c == 'r' || c == 'R'){
printf("w");
}else if(c == 'e' || c == 'E'){
printf("q");
}else if(c == '\''){
printf("l");
}else if(c == ';'){
printf("k");
}else if(c == 'l' || c == 'L'){
printf("j");
}else if(c == 'k' || c == 'K'){
printf("h");
}else if(c == 'j' || c == 'J'){
printf("g");
}else if(c == 'h' || c == 'H'){
printf("f");
}else if(c == 'g' || c == 'G'){
printf("d");
}else if(c == 'f' || c == 'F'){
printf("s");
}else if(c == 'd' || c == 'D'){
printf("a");
}else if(c == '.'){
printf("m");
}else if(c == ','){
printf("n");
}else if(c == 'm' || c == 'M'){
printf("b");
}else if(c == 'n' || c == 'N'){
printf("v");
}else if(c == 'b' || c == 'B'){
printf("c");
}else if(c == 'v' || c == 'V'){
printf("x");
}else if(c == 'c' || c == 'C'){
printf("z");
}else if(c == 's' || c == 'S'){
printf("]");
}else if(c == 'a' || c == 'A'){
printf("[");
}else if(c == 'x' || c == 'X'){
printf("\\");
}else if(c == 'z' || c == 'Z'){
printf("\'");
}
}

UVA Problem#10018

Question:

Solutions :
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

char s1[100], s[100], s2[100];

void add(char f[], char s[], char r[]){
int lf, ls, d=0, i, j=0, c=0, sum;
lf=strlen(f); ls=strlen(s);
reverse(f, f+lf); reverse(s, s+ls);
if(lf>=ls){
d=lf-ls;
for(i=0; i<ls; i++){
sum = f[i]+s[i]-96+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
for(i=ls; i<lf; i++){
sum = f[i]-48+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
if(c!=0){
sum = c%10;
r[j++] = sum+48;
if(c>9)r[j++] = (c/10)+48;
}
r[j] = '\0';
lf = strlen(r);
reverse(r, r+lf);
}else{
d=lf-ls;
for(i=0; i<lf; i++){
sum = f[i]+s[i]-96+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
for(i=lf; i<ls; i++){
sum = s[i]-48+c;
r[j++] = (sum%10)+48;
c = sum/10;
}
if(c!=0){
sum = c%10;
r[j++] = sum+48;
if(c>9)r[j++] = (c/10)+48;
}
r[j] = '\0';
lf = strlen(r);
reverse(r, r+lf);
}
}

UVA Problem#543

Question:

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

int prime(int n){
int i, c=1, j=int(sqrt(n));
for(i=2; i<=j; i++){
if(n%i==0){
c = 0;
break;
}
}
return c;
}

UVA Problem#458

Question:

Solutions :
#include<stdio.h>
#include<string.h>

char s[1000000];

int main(){
int i, l, c;
while(gets(s) != NULL){
l = strlen(s);
for(i=0; i<l; i++){
c = s[i]-7;
printf("%c", c);
}
printf("\n");
}
return 0;
}

UVA Problem#424

Question:

Solution: 
char f[100000], s[100000], r[100000]; 
void add(char f[], char s[], char r[]){ 
int lf, ls, d, i, j=0, c=0, sum; lf=strlen(f);
ls=strlen(s); 
reverse(f, f+lf); 
reverse(s, s+ls); 

UVA Problem#382

Question:

Solution: 
void perfection(int n){
int i , sum=0, m=n/2; 
for(i=1; i<=m; i++){ 
if(n%i==0)
sum += i; 
}
if(n>sum){ 
printf("DEFICIENT\n"); 
}
else if(n<sum){ 
printf("ABUNDANT\n"); 
}
else if(n == sum){
printf("PERFECT\n"); 
}
  int main(){
....
.... 
}  

Friday, October 9, 2009

The Art of Computer Programming by Donald E. Knuth (Boxed_Set_Vol_1-4.part2)

The Art of Computer Programming by Donald E. Knuth. The link to download the 2nd part of the book is given below.

click here to download

The Art of Computer Programming by Donald E. Knuth (Boxed_Set_Vol_1-4.part2)

The Art of Computer Programming by Donald E. Knuth. The link to download the 2nd part of the book is given below.

click here to download

The Art of Computer Programming by Donald E. Knuth (Boxed_Set_Vol_1-4.part1)

The Art of Computer Programming by Donald E. Knuth. Here is the link to download the 1st part.


click here to download

A Computational Introduction To Number Theory And Algebra

A Computational Introduction to Number Theory by Victor Shoup

click here to download

Password to unzip/unrar: www.ebooksdb.com

Thursday, October 8, 2009

UVA Problem#10432

Question:

Solution technique: 
1. take inputs 
2. define pi as acos(-1.0) 
3. use the formula below to find the output:
area = (n*r*r*(sin(2.0*pi/n)))/2; 
  

UVA Problem#10370

Question:

Solution:
1. take inputs c, n, and the numbers in an array a[]
2. add all the elements of the array and find the average.
3. now check for the following condition and print the result:

int main(){
....
..... 
for(j=0; j>n; j++){ 
if(a[j]<avg)count++; 
r = (count/n)*100; 
printf("%.3lf%c\n", r, d);   
 }

Wednesday, October 7, 2009

Big Mod (uva#374)

Question:

Solutions :
long bigmod(long b, long p, long m){
if(p==0)
return 1;
else if(p%2==0)
return ((bigmod(b, (p/2), m))*(bigmod(b, (p/2), m)))%m;
else return((b%m)*bigmod(b, p-1, m))%m;
}
  

Fibonacci using quick matrix

Solutions :

int fibo(int n){       // using quick method matrix program
int i, h, j, k, t;
i=h=1;
j=k=0;
while(n>0){
if(n%2==1){
t=j*h;
j=i*h + j*k +t;
i= i*k + t;
}
t= h*h;
h=2*h*k + t;
k= k*k +t;
n= (int) n/2;
}
return j;
}

Fibonacci using dynamic program

Solutions :

int fibo(int n){      // // using dynamic program
int a=1, b=1, i, c;
for(i=2; i>=n; i++){
c=a+b;
a=b;
b=c;
}
return a;
}

Fibonacci using normal recursion

Solutions :

int fibo(int n){    // using normal recursion
if(n<2) return (fibo(n-1)+fibo(n-2));
if(n==0) return 0;
else return (1);
}

Ins and outs of Fibonacci numbers

here is a describe document on fibonacci number. Almost everything of it....

click here to view/download

Ins and outs of Fibonacci numbers

here is a describe document on fibonacci number. Almost everything of it....

click here to view/download

Divisibility rules

here is another important topics on the various rules of divisibility.

click here to download

Divisibility rules

here is another important topics on the various rules of divisibility.

click here to download

Bit wise operator

Using of Bit wise operators instead of any other mathematical operators is much more faster. here is a document of its uses.

click here to download

Bit wise operator

Using of Bit wise operators instead of any other mathematical operators is much more faster. here is a document of its uses.

click here to download

Monday, October 5, 2009

Programming Challenges- the Programming Contest Training Manual

Programming Challenges- the Programming Contest Training Manual by Steven S.Skiena and Miguel A.Revilla.

click here to download

Java 2-The Complete Reference (fifth edition)-Herbert Schildt

 Java 2-The Complete Reference (fifth edition)-Herbert Schildt........another useful book to learn JAVA language.

click here to download

UVA Problem#100

Question:

Solution:
1. take input i, j. let x=i, y=j. 
2. Generate the series.
for(a=i; a<=j; a++){ 
n=a; 
count=1; 
while(n!=1){
if(n%2==0){ 
n = n/2; 
}
else{ 
n = 3*n+1; 
count++; 
}  

3. find the max count value by 
if(maxcount < count){ 
maxcount=count; 

JAVA How to Program (7th Edition) by Deitel and Deitel

A complete java book full of examples. "JAVA How to Program (7th Edition) by Deitel and Deitel".

click here to download