Showing posts with label PROGRAMING. Show all posts
Showing posts with label PROGRAMING. Show all posts

UVA: 490 - Rotating Sentences - Solution in C/C++


Problem Name:  Rotating Sentences

Problem Source: Uva Online Judge

Problem No: 490

Problem Difficulty: Easy

Problem Link: Here

Submit Solution Here

Important Point

  • You must have to assign a white space to every null value of every sentence.
  • Top sentence will be on right most and last sentence will be on left most.
  • You have to print every character including white space. 
Source Code


 #include<bits/stdc++.h>  
 using namespace std;  
 //Code Written by Al Shah Reyaj  
 //BSMRSTU, Gopalganj, Bangladesh  
 int main()  
 {  
   char s[105][105];  
   int c=0,m=0,l;  
   for(int i=0;i<105;i++)  
   {  
     for(int j=0;j<105;j++) s[i][j]=' ';  
   }  
   while(gets(s[c]))  
   {  
     l=strlen(s[c]);  
     if(l>m) m=l;  
     c++;  
   }  
   for(int i=0;i<m;i++)  
   {  
     for(int j=c-1;j>=0;--j)  
     {  
       if(s[j][i]=='\0') cout<<' ';  
       else  
       cout<<s[j][i];  
     }  
     cout<<endl;  
   }  
   return 0;  
 }  


Thanks for Reading This. Check our more Activities.

UVA: 100 - The 3n + 1 problem - Solution in C/C++



Problem Name: The 3n+1 problem

Problem Source: Uva Online Judge

Problem No: 100

Problem Difficulty: Easy

Problem Link: Here

Submit Solution Here

Important Point

  • i can be bigger than j. if i is bigger than j then you have to run the loop from j to i;
  • i and j in the output must be same as input.
  • You have to count n=1 case.
  • You don't have to use long long. int is enough.
  • You have to run the loop including i and j.

Source Code


#include<bits/stdc++.h>  
 using namespace std;  
 //Code Written by Al Shah Reyaj  
 //BSMRSTU, Gopalganj, Bangladesh  
 /* ******* ****    **    *******  
   *   *  **    * *      *  
   *  *  **   *  *     *  
   ****   **   ********    *  
   * *   **  *    *   *  
   *  *   **  *     *  *  
   *  *  **** *      * *******  
 */  
 int fin(int n,int c)  
 {  
   c++;  
   if(n==1) return c;  
   if(n%2!=0) fin((3*n)+1,c);  
   else fin(n/=2,c);  
 }  
 int main()  
 {  
   int a,b;  
   while(cin>>a>>b)  
   {  
     int m=0;  
     int x=a,y=b;  
     if(a>b)  
     {  
       int x=a;  
       a=b;  
       b=x;  
     }  
     for(int i=a; i<=b; i++)  
     {  
       int l=fin(i,0);  
       if(l>m) m=l;  
     }  
     cout<<x<<" "<<y<<" "<<m<<endl;  
   }  
   return 0;  
 


Thanks for Reading This. Check our more Activities.

Start Programming With C - Part 1

Hello & Welcome!!

Here, We are going start a new Tutorial series. In this series we are going to learn programming with C. 



Why C??

Well, Good question. C is called the mother of programming language. It's the closest language to computer. We know computer can't understand any kind of language. It's only know true or false. We have to use a software called compiler to make it understood our program. Compiler compile the code to machine language or binary representation.Then only computer can understand it.
C is closest language to machine language. So, if we learn C, we could go to close to computer. And also if you learn C well, will can learn any other one easily. That's why C...

No more talk....Lets start...

First, We need a compiler to write and compile the code. We will use Codeblocks as compiler. So, go to this link and download codeblocks. After completing the download install the setup. After installing you will see the shortcut icon on desktop. Open it!!

Now, you will see like this. 


Now, we have to create a new file to start programming. For creating a new .c file 

Click> File>New>Empty File

or

Press> Ctrl+Shift+N


     
Now, you will see like this. So, this our main window, We will program here.


Now, before starting programming, we have to save it. So,

Click>File>Save

or

Press>Ctrl+S

Save the file. 

Now, Lets start programming.....!!

First type these...

#include<stdio.h>

int main()
{
    return 0;
}

Typed it?? Lets learn what is it??

#include<stdio.h>

by typing this we have included stdio header file. This is the way to add a file in C language. So, what is header file and what is stdio header file? Why we include it? Header file is pre-maded  file where some function are included. We can use those function by including the header file. There are some header file. Such as, stdio.h, math.h, string.h ......

stdio means standard input output. In this header file some function are included for some basic work such as take input or giving output. That's why we included it.

Next, we are seeing int main(). This is a function and it's the main function a program. We will do all of our programming in this function. For any function we have to use {}. { means starting of a function and } means end of a function. That's why we use it for main function and write a thing return 0; in it. We have written int before main(). It means this main function return integer type value. int is the short form of integer and we will use it in all of our program.

Now, lets come to return 0; .We  will write this at the end of the program. When we will run this program, return return something to the function. and return 0 return nothing. 0 means nothing.
We have used a semicolon at end of the return 0. It means the end of the statement. We have to use it for all statement. 

So, these are the basic thing for writing a program. We have to use it for all program.

Now, we will learn a function which is included in stdio.h header file. Look at this function.

printf();

This is function for printing something. We will use it for printing something. For doing this we will write something in these two ().

Lets write and run our first program.

#include<stdio.h>

int main()
{
    printf("Hey You!!");
    return 0;
}

We tell to print Hey You!! . We will use "" for printing anything.
For running this go to Build>Build and run or Press>F9.

You will see....


So, Congress!! You have done your first program. So, keep going.

That's all for today. Hopefully learned something. See you on Next tutorial..... 

DOWNLOAD PC GAMES

DOWNLOAD PC APPS