UVa : 11917 (Do Your Own Homework!)

UVa : 11917 (Do Your Own Homework!)

 

 

#include <bits/stdc++.h>

using namespace std;

int main()

{



    int n;

    cin>>n;

    int tc=1;

    while(n--)

    {

        int input;

        cin>>input;

        map<string,int>m;

        string s;

        int d;

       

    for(int i=1;i<=input;i++)

    {

        cin>>s>>d;

        m[s]=d;

    }

       

        int D;

        cin>>D;

        string k;

        cin>>k;

        printf ("Case %d: ", tc++);



        if ( m [k] && m [k] <= D )

         printf ("Yesss\n");

        else if ( m [k] && m [k] <= D + 5 )

         printf ("Late\n");

        else

        printf ("Do your own homework!\n");

   

    }

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVa 11931 Solution- Maze Escape

 

 

#include <bits/stdc++.h>

using namespace std;

int main()

{

    unsigned long int d,q;

    int i,count,j,bn[1000];

    while(scanf("%lu",&d)==1)

    {

        if(d==0) break;

        i=0;

        q=d;

       

        while(q!=0)

        {

            bn[i++]= q%2;

            q/=2;

        }

        count=0;

        printf("The parity of ");

        for(j=i-1;j>=0;j--)

        {

            printf("%d",bn[j]);

            if(bn[j]==1)

            count++;

        }

        printf(" is %d (mod 2).\n",count);

    }

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

Uva 11934 Solution – Magic Formula

 

 

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int a,b,c,d,l,fn,count;

    while(cin>>a>>b>>c>>d>>l)

    {

        if(a==0 and b==0 and c==0 and d==0 and l==0) break;

        count=0;

        for(int i=0;i<=l;i++)

        {

           

        fn=a*i*i + b*i +c;

        if(fn%d==0)

        count++;

       

        }

        cout<<count<<endl;

    }

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVA Problem 11942 Solution – Lumberjack Sequencing

 

#include<bits/stdc++.h>

using namespace std;

int main()

{

   int tc,a[13];



    scanf ("%d", &tc);



    printf ("Lumberjacks:\n");



    while ( tc-- )

     {

        for ( int i = 0; i < 10; i++ ) {

            scanf ("%d", &a [i]);

        }



        bool flag = true;



        if (a [0] > a [1])

         flag = false;



        bool res = true;



        if (flag) {



            for ( int i = 1; i < 10; i++ ) {

                if (a [i] < a [i - 1])

                res = false;

            }



        }

         else

        {



            for ( int i = 1; i < 10; i++ )

             {

                if (a [i] > a [i - 1])

                res = false;

            }

        }



        if (res)

            printf ("Ordered\n");

        else

            printf ("Unordered\n");



    }



    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVA-Solutions 11945 – Financial Management.

 

#include<bits/stdc++.h>

using namespace std;

int main()

{

int t;

double d, sum;

int j=0;

scanf(“%d”,&t);

while(t–)

{

sum = 0;

for(int i=0; i<12; i++)

{

scanf(“%lf”,&d);

sum = sum + d;

}

double avg = sum/12.00;

printf(“%d $”,++j);

if(avg<=999999.0 && avg>999.0)

{

int a = avg/1000.0;

printf(“%d,”,a);

avg = fmod(avg,1000.0);

}

printf(“%.2lf\n”,avg);

}

return 0;

}

UVa : 11917 (Do Your Own Homework!)

UVA Problem 11988 Solution – Broken Keyboard

 

 

#include <bits/stdc++.h>

#include <vector>



using namespace std;

char letters[100001];



int main()

{

    int i;

   

    while ( scanf ("%s", &letters) != EOF ) {



        int l = strlen (letters);



        list <char>beiju;

   

    list <char>::iterator it = beiju.begin();

   

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



            if ( letters [i] == '[' ) it = beiju.begin();

            else if ( letters [i] == ']' ) it = beiju.end();

            else beiju.insert(it, letters [i]);

        }



        for ( it =beiju.begin(); it != beiju.end(); it++ )

   

    printf("%c",*it);



     printf ("\n");

   

}

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVa : 11991 (Easy Problem from Rujia Liu?)

 

 

#include <cstdio>

#include <vector>

using namespace std;



int main() {

    int n, m, N,V, k;

    vector<vector<int> > v;

    while (scanf("%d %d", &n, &m) != EOF) {

        v.assign(1000000, vector<int>());



        for (int i = 1; i <= n; i++) {

            scanf("%d", &N);

            v[N].push_back(i);

        }



        for (int i = 0; i < m; i++) {

            scanf("%d %d", &k, &V);



                if ( v [V].size () < k ) printf ("0\n");

           

            else printf ("%d\n", v [V] [k - 1]);

        }

    }



    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVA Problem 12527 Solution – Different Digits

 

 

#include<stdio.h>



int main()

{

int n,m,ro,a[20],num,i,j,digit,k,count;

while(scanf("%d %d",&n,&m)==2)

{

    ro=0;

    for(i=n;i<=m;i++)

    {

        num=i;

        digit=0;

        while(num>0)

        {

           a[digit++]=num%10;

            num/=10;

        }

        count=0;

        for(j=0;j<digit-1;j++)

        {

            for(k=j+1;k<digit;k++)

            {

                if(a[j]==a[k])

                {

                    count=1;

                    break;

                }

            }

           

        }

        if(count==0)

        {

            ro++;

        }

  

    }

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

}

return 0;



}

 

UVa : 11917 (Do Your Own Homework!)

UVA Problem 12895 Solution -Armstrong Number

 

 

#include <bits/stdc++.h>

using namespace std;



int main()

{

    int

   

    num,tc,sum,j;

   

    vector<int>v;

   

    cin>>tc;

   

    while(tc--)

    {

        cin>>num;

       

        v.push_back(num);

       

        int tempo=num;

       

        int i=0;

       

        while(tempo)

        {

            v[i]=tempo%10;

            tempo/=10;

            i++;

        }

   

        for(sum = j =0;j<i;j++)

        {

            sum = sum + pow(v[j],i);

        }

   

        if(sum == num)

        {

            cout<<"Armstrong\n";

        }

   

        else

        {

            cout<<"Not Armstrong\n";

        }

    }

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVA-Solutions 11677 (Alarm Clock)

 

 

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int h1,m1,h2,m2,hr,mr,tr;

    while(cin>>h1>>m1>>h2>>m2)

    {

       

        if(h1==0 && m1==0 && h2==0 && m2==0) break;

        hr=h2-h1;

        mr=m2-m1;

        tr=(hr*60)+mr;

       

        if(tr<0)

        {

            tr+=24*60;

        }

        cout<<tr<<endl;

    }

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVA Problem 10773 – Back to Intermediate Math



#include <bits/stdc++.h>

using namespace std;

int main()

{

    double d,u,v,t1,t2;

    int count,n;

    cin>>n;

    count=1;

    while(n--)

    {

       

        cin>>d>>v>>u;

       

         if(u==0 ||v==0 ||u<=v)

         {

             printf("Case %d: can't determine\n",count);

             continue;

         }

       

       

         t1=d/u;

        t2=d/sqrt(u*u-v*v);

        printf("Case %d: %.3lf\n",count,t2-t1);

        count++;

    }

    return 0;

}

 

UVa : 11917 (Do Your Own Homework!)

UVA 11462 (Age sort) Solution

//UVA Problem 11462 Solution /** * @Author : Jesmin Akther */


#include <stdio.h>

long int n, array[2000005], c, d, t;

int main()

{

  while(scanf("%ld", &n)==1 )

 {

     if(n==0) break;

     for (c = 0; c < n; c++)

      {

    scanf("%ld", &array[c]);

  }



  for (c = 1 ; c <= n - 1; c++) {

    d = c;



    while ( d > 0 && array[d] < array[d-1]) {

      t          = array[d];

      array[d]   = array[d-1];

      array[d-1] = t;



      d--;

    }

  }



  for (c = 0; c < n ; c++) {

    printf("%ld", array[c]);

    if(c<(n-1))

    printf(" ");

   

  }

 printf("\n");

 }

  return 0;

}

 

Part 2: Method Signature in Java with Example.

Part 2: Method Signature in Java with Example.

Method Signature in Java:

Firstly need to know what is java method? why to use in java?

Java method refers, a method which is a block of code which only runs when it is called. Here data can pass as parameters into a method. Methods are used to perform certain actions, and they are also known as functions.

Use:

This is mainly use to frequent use a same function by call that is reuse a function.

To create a method must be declared within a class. It is followed by parentheses () with the name of the method. Java provides some pre-defined methods, such as System.out.println(), though  can also create  own user define methods to perform secific actions:

Example
Create a method inside Tree:

public class Tree{
static void treeMethod() {
// code to be executed
}
}

Example Explained

  • treeMethod() is the name of the method.
  • static means that the method belongs to the Main class and not an object of the Tree class.
  • void means that this method does not have a return value.

Now with another example brief it shortly:

Next need to know what  is method signature and it’s declaration. It is refers to a method-name to parameter-list before body part of a java class.

An example of method declaration:

public double showValue(int types,double area)
{

    //to do

}

So in method declaration uses components are:

modifiers: It controls the access level,

Modifier Description
public The public use in code which mean it is accessible for all classes.
private This Modifier refers the code is only accessible within the declared class
default The code is only accessible in the same package. This is used when  don’t want to specify a modifier.
protected The code is accessible in the same package and subclasses.

return type: A return type may be a primitive type. For instance int, float, double, a reference type or void type(returns nothing),

method name: A method name  should follow the camel case. First letter of the first word should be small and the first letters of the remaining words should be capital,

parameter list in parenthesis: Parameters act as variables inside the method.

public class Main
{
static void mMethod(String first_name)

{
System.out.println(first_name );
}

public static void main(String[] args)

{
mMethod("Harun");
mMethod("Roshid");
}
}

Output:

Harun

Roshid

exception list: Java Built-in exceptions are suitable to explain certain error situations. It also supports  users to define their own exceptions.,

  • ArithmeticException
    This exception is thrown in code when an exceptional condition has occurred in an arithmetic operation.
  • ArrayIndexOutOfBoundsException
    It is thrown to indicate that an array has been accessed either negative or greater than or equal to the size of the array.

the method body: The method body is where all of the action of a method takes place,

enclosed between braces: Start to end body of a Java class .

Among these components(six total) only two comprises the method signature.

  • a method name,
  • parameter list in parenthesis

Following the example the method signature :

showValue( int types, double area)

That means, method signature is part of the method declaration , combination of the method name and the parameter list.  Overloading method signature get emphasis to its ability to write methods that have the same name but accept different parameters.

Through the method signatures ,  Java compiler can discern the difference between the methods at compilation time.

Method Signature Examples:

public double showValue(int types,double area,float result) {

    //to do

}

The method signature in the above example is showValue (int, double, float)

public double showValue(String name) {

    //to do

}

 

The Java compiler will let us add another method like the above example because its method signature is different showValue(String) in this case.

To Call a Method :

we discuss before in Java, write the method’s name followed by two parentheses () and a semicolon;

In the following example, treeMethod() is used to print a text (the action), when it is called:

Example
Inside main, call the treeMethod() method:

public class Tree {
static void treeMethod() {
System.out.println("hello executed treeMethod!");
}

public static void main(String[] args) {
treeMethod();
}
}

// Outputs “hello executed treeMethod!”

The method can be called multiple time. Above code main method rewrite for this code:

public static void main(String[] args) {
treeMethod();

treeMethod();

treeMethod();
}
}

// Here treeMethod() call three times and everytime shows same output

Java Method Parameters and Arguments:

Value can be passed to methods as parameter. Parameters act as variables inside the method.
Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.

public class Tree {
static void myMethod(String languageName) {
System.out.println(languageName+ " language");
}

public static void main(String[] args) {
myMethod("Python");
myMethod("C");
myMethod("C++");
}
}

// Python language
// C language
// C++ language

Java can support Multiple Parameters. You can have as many parameters as you like:

Example

public class Tree{
static void myMethod(String languageName, (String version) {
System.out.println(languageName + " is a" + age);
}

public static void main(String[] args) {
myMethod("Python", "language");
myMethod("C", "language");
myMethod("C++", "language");
}
}

// Python is a language
// C is a language
// C++ is a language

Draftsbook is a learning base blog. The blog share Article series based on Subject. For example:

    1. JAVA : JAVA  is a object-oriented programming(OOP) language. This language classes and objects are the two main aspects of OOP. The blog content discuss below principles of OOP:
      1. Encapsulation
      2. Inheritance
      3. Abstraction
      4. Polymorphism
  1. Data Structure: Data structure refers a several way of organizing data in a computer system.
  2. Android : Android software development  apps can be written using Kotlin, Java, and C++ languages” using the Android software development kit (SDK). This blog contains  android feature Navigation drawer implementation and its usage are mention.
  3. IELTS : IELTS  Four module with strategies are written hereby

5.Problem Solving : Problem solution on various online platform tips and solution are given here following platform.

C program reverse a given string without using build in function.

C program reverse a given string without using build in function.

C:

Reverse a given string without using build in function

 

 

#include <stdio.h>
#include<string.h>
int main()
{

char string1[100],string2[100];
char s[]="Learn and share blog";
int i,j,k,count;
for(count = 0; s[count] != '\0'; count++);
for(j=count-1,i=0 ;j>=0; j--)
{
    string1[i]=s[j];
    i++;
}
string1[i]='\0';
printf("reverse string is : %s",string1);
return 0;
}

output:

reverse string is : golb erahs dna nraeL