Showing posts with label C-Prom 2015. Show all posts
Showing posts with label C-Prom 2015. Show all posts

Sunday, August 14, 2016

Best Application to learn Difference Programming Languages Fast


App Name: Programming Hub
Package Name: com.freeit.java
Category: Education
Developer : Nexino Labs Pvt Ltd
Version: 3.0.6
Publish Date: July 30, 2016
File Size: Undefined
Installs: 1,000,000 - 5,000,000
Requires Android: 4.1 and up
Content Rating: Everyone
Developer: Visit website Email contactus@prghub.com


This is the best Application for me to Learn 18+ Programming languages such as Python, Assembly, HTML, VB.NET, C, C++, C# (CSharp), JavaScript, PHP, Ruby, R Programming, CSS, Java programming and much more! The new UI is quite interesting with new Material Design include the built-in playground where you can test your code in one app :D

With this app, i think is fastest way to learn any programming language by referring ready made programs and theory created by programming experts. Just download the language you want to learn or just request to the developer on what language you want or solutions.

Have an exam tomorrow?? :D No worries! By this app, forget your 600 page textbooks! Simply read this app essential and very precise reference material to score awesome marks!

Below is the Screenshot of this lastest app





Wednesday, September 16, 2015

The Mirror (CPROM UiTM Arau 2015)

Mirror is an object that reflects most of detailed physical characteristics of original light. In other word, you can create a duplicated image of identical physical characteristics using a mirror. Same goes when the string characters are placed in front of the mirror.

Input 
First line of input contains an integer N (1 ≤ N ≤ 5) to indicate number of test cases. Following the first line are the test cases. Each line of a test case contains a string data with character, C (C > 0).
The input must be read from standard input.

Output
The output of the program should display the original string concatenated with the mirrored string.
The output must be written to standard output.




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q10{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
            
      int cases = scan.nextInt();
      
      String [] ans = new String[cases];
            
      for(int x=0;x<cases;x++){
         String get = scan.next();
         
         StringBuilder str = new StringBuilder(get);
         get = get+str.reverse().toString();
         
         ans[x] = get;         
      }
      
      for(int x=0;x<cases;x++){
         System.out.println(ans[x]);
      }
   }
}


Judge Answer in Java


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import.java.util.Scanner;
public class Mirror {
    public static void main(String[] args) {
        Scanner sc = newScanner(System.in);
        intN = sc.nextInt();
        String testCase[] = new String[N];
        for (inti = 0; i < N; i++) {
            testCase[i] = sc.next();
        }
        for (inti = 0; i < N; i++) {
            for (intj = testCase[i].length() - 1; j >= 0; j--) {
                testCase[i] += testCase[i].charAt(j);
            }
            System.out.println(testCase[i]);
        }
        sc.close();
    }
}

Odd Stars (CPROM UiTM Arau 2015)

Write a program that is able to print a star-shaped matrix.

Input 
An odd integer number.
Output 
A star-shaped matrix.




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q9{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
            
      int in = scan.nextInt();
      int mid = (in/2);
      for(int x=0;x<in;x++){
         for(int y=0;y<in;y++){
            if(y == mid)
               System.out.print("*");
            else if(x == y)
               System.out.print("*");
            else if(x==mid)
               System.out.print("*");
            else if(y == (in-1)-x)
               System.out.print("*");
            else
               System.out.print(" ");
               
         }
         
         System.out.println();
      }
   }
}


Judge Answer in C++


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream> 
#include <math.h> 
using namespace std;
int main() {
    int size;
    cout<<"Enter an odd integer: ";
    cin>>size;
    char star[size][size];
    int center = ceil (size/2);
    for (int i = 0;
    i < size;
    i++) {
        for (int j = 0;
        j < size;
        j++) {
            if (j == center) cout<<"*";
            else if (i == center) cout<<"*";
            else if (i == j) cout<<"*";
            else if (i + j == size - 1) cout<<"*";
            else cout<<" ";
        }
        cout<<"n";
    }
    system("pause");
    return 0;
}

Character Classifier (CPROM UiTM Arau 2015)

In any programming languages, characters can be classified into several categories such as digit, alphabet, symbol, uppercase, lowercase etc. The classification can be done using built-in functions available in the compiler.

Input  
The first line of the input contains the number of strings to be tested. Following the first line are the test cases.  

Output  
The output of the program should print the statistics of character categories.
The output must be written to standard output.




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q8{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);      
 
      int cases = scan.nextInt();
            
      for(int x=0;x<cases;x++){
         String get = scan.next();
         
         int countd=0,countl=0,counts=0,countu=0,countlo=0;
         for(int y=0;y<get.length();y++){
            if(Character.isDigit(get.charAt(y)))
               countd++;
            else if(Character.isLetter(get.charAt(y))){
               countl++;
               
               if(Character.isUpperCase(get.charAt(y)))
                  countu++;
               else if(Character.isLowerCase(get.charAt(y)))
                  countlo++;
            }
            else
               counts++;
            
         }
         
         System.out.println("Digit:"+countd+"\nAlphabet:"+countl+"\nSymbol:"+counts+"\nUppercase:"+countu+"\nLowercase:"+countlo+"\n");
         
      }

   }
}


Judge Answers in C++


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream.h> 
#include<ctype.h>
void main() {
    int i, alpha, digit,upper,lower,punc;
    char testcase[10][40];
    int num;
    cin>>num;
    for(int j=0;
    j<num;
    j++) {
        cin>>testcase[j];
    }
    for(j=0;
    j<num;
    j++) {
        alpha=0, digit=0,upper=0,lower=0,punc=0,i=0;
        while (testcase[j][i]!= '')  {
            if (isdigit(testcase[j][i])) {
                digit++;
            }
            else if (isalpha(testcase[j][i])) {
                alpha++;
                if (isupper(testcase[j][i]))  upper++;
                else if (islower(testcase[j][i]))  lower++;
            }
            else if (ispunct(testcase[j][i])) {
                punc++;
            }
            i++;
        }
        cout<<endl;
        cout<<"Digit: "<<digit<<endl;
        cout<<"Alphabet: "<<alpha<<endl;
        cout<<"Symbol: "<<punc<<endl;
        cout<<"Uppercase: "<<upper<<endl;
        cout<<"Lowercase: "<<lower<<endl;
    }
}

Analogous Issues (CPROM UiTM Arau 2015)

You are given an analogy of the form A::B, where B is an anagram of the word A. You must compute the same analogy for a similar-sized word M by rearranging the letters of M to create a new word N in the same way as described by the analogy.

For example, given the analogy RAIN::IRAN above, the similar analogy for the word ACRE is RACE. Note how the shuffling of letters from A to B is replicated to create N from M. The word A contains no duplicate letters. The same is true for B and M. All strings (A, B, M and N) will have between 2 and 10 characters each.

Input
The first line of the input contains the analogy in the form of two strings A and B of the same length separated by two colons (“::”). The second line will contain a string M of the same length as A and B.  
Output
The output of the program should print the result of single string representing the analogy for the input word M. The length of this output string must be the same as the length of M.
The output must be written to standard output.




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q7{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);      
      
      String[] samples = scan.next().split("::");
      String str = scan.next();
      
      int[] arrange = new int[str.length()];
      
      String fstpermu = samples[0];
      String secpermu = samples[1];
      for(int x=0;x<fstpermu.length();x++){
         arrange[x] = secpermu.indexOf(fstpermu.charAt(x));
      }            
      
      String rearrange = "";
      for(int x=0;x<arrange.length;x++){
         for(int y=0;y<arrange.length;y++){
            if(x == arrange[y])
               rearrange = rearrange + str.charAt(y);
         }
      }
      
      System.out.println(rearrange);

   }
}

Counting Pixels (CPROM UiTM Arau 2015)

Consider printing an MxN rectangular grid of square boxes where each box has height and width of B pixel. Each black dot on the printed grid represents a single pixel. Your task is to compute the total of black dots to be used in printing the grid. The following example shows the calculation of the pixels:

Let B = 5, M=2, and N = 3. In this sampel, the total pixels is 63

Input
The first line of the input contains an integer T (1 ≤ T ≤ 5), the number of test cases. Following the first line are the test cases. Each line of a test case contains a single positive integer representing the size of each square box (B), the number of rows (M) and the number of columns (N), in the grid.
The input must be read from standard input.

Output
The output of the program should display a single integer representing the total number of pixels used to print the grid.

Samples Input
3
5 1 2
4 3 3
4 4 3

Samples Output
27
64
82


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q6{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);      
      int cases = scan.nextInt();
            
      for(int x=0;x<cases;x++){
         String [] get = scan.next().split(" ");
         
         int B = Integer.parseInt(get[0]);
         int M = Integer.parseInt(get[1]);
         int N = Integer.parseInt(get[2]);
         
         System.out.println(((B-2)*M*(N+1))+((M+1)*((B*N)-(N-1))));       
      }

   }
}

Numbers of Words (CPROM Uitm Arau 2015)

Write a program that is able to calculate the number of words used in a complete sentence. The program will count repeated words, as one. The program will also ignore punctuation symbols used in a sentence such as comma (,) and period (.) characters.

Input
A complete sentence.
Output 
An integer representing the number of distinctive words used in the given sentence.


Samples Input
Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall.

Whether the weather is warm, whether the weather is hot, we have to put up with the weather, whether we like it or not.

Samples Output
9
16


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Solved by Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q5{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
      
      String str = scan.next();
      str = str.replace(",","").replace(".","").toLowerCase();

      String[] get = str.split(" ");
      List<String> list = Arrays.asList(get);
      Set<String> set = new HashSet<String>(list);
      
      String []newstr = new String[set.size()];
      set.toArray(newstr);
               
      System.out.print(newstr.length);
   }
}


Judge Answer in Java


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
importjava.util.*;
public class wordsCountDifferent {
    public static void main(String args[]) {
        String sentence;
        ArrayListwordsAL = new ArrayList();
        Scanner in = new Scanner(System.in);
        intsame_words = 0;
        char[] tSentence = new char[1000];
        intnewWordCount = 0;
        String nSentence = " ";
        System.out.print("Enter a sentence: ");
        sentence = in .nextLine();
        for (int index = 0; index < sentence.length(); index++) {
            if (sentence.charAt(index) != ',' && sentence.charAt(index) != '.') {
                tSentence[newWordCount] = sentence.charAt(index);
                newWordCount++;
            }
        }

        nSentence = nSentence.copyValueOf(tSentence, 0, newWordCount);
        for (String word: nSentence.split(" ")) {
            wordsAL.add(word);
        }
        ArrayListdiffList = new ArrayList();
        intdiffIndex = 0;
        String word1;
        String word2 = " ";
        int flag = 0;
        for (int index = 0; index < wordsAL.size(); index++) {
            word1 = (String) wordsAL.get(index);
            if (diffIndex == 0) {
                diffList.add(diffIndex, word1);
                diffIndex++;
            } else {
                flag = 0;
                for (int counter = 0; counter < diffList.size(); counter++) {
                    word2 = (String) diffList.get(counter);
                    if (word1.equalsIgnoreCase(word2)) {

                        flag = 1;
                        counter = diffList.size();
                    }
                }
                if (flag == 0) {
                    diffList.add(diffIndex, word1);
                    diffIndex++;
                }
            }
        }
        System.out.println("Size of diffList =  " + diffList.size());
    }
}

Count Even and Odd Numbers (CPROM Uitm Arau 2015)

Input
The number of input must be determine by the user. After that, based on the integer entered by user, determine whether the integer is an odd or even number to count the total number of even and odd number.
The input must be read from standard input.

Output
The output of the program should display the total of odd and even number.
The output must be written to standard output.


Samples Input
6
1
2
3
4
5
6

Output
3
3


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q4{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
            
      int cases = scan.nextInt();
      int counte=0,counto=0;
            
      for(int x=0;x<cases;x++){
         int in = scan.nextInt();
         
         int temp = (in%2 == 0)?counte++:counto++;        
      }
      
      System.out.println(counte);
      System.out.println(counto);
   }
}

Search and Replace (CPROM Uitm Arau 2015)

Five of the 26 alphabet letters are vowels: A, E, I, O, and U.  Search and replace the vowels in the sentences or paragraph with certain symbol of character.  The symbol which assign to each vowel like in  below:-

Input 
The input should be the sentence of string values.
Output 
The output of the program should display as shown at below.


Input
Cat is a small domesticated carnivorous mammal with soft fur, a short snout, and retractile claws.

Output
C$t #s $ sm$ll d&m@st#c$t@d c$rn#v&r&%s m$mm$l w#th s&ft f%r, $ sh&rt sn&%t, $nd r@tr$ct#l@ cl$ws.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q3{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);

      String get = scan.next();
      
      String str = get.replace("a","$");
      str = str.replace("A","$");
      str = str.replace("e","@");
      str = str.replace("E","@");
      str = str.replace("i","#");
      str = str.replace("I","#");
      str = str.replace("o","&");
      str = str.replace("O","&");
      str = str.replace("u","%");
      str = str.replace("U","%");
         
      System.out.print(str);
   }
}

Judge Answers in C++



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream> 
#include<string.h>
using namespace std;
int main() {
    char sentence[300];
    //declaration string //user input 
    cout<<"Please enter string of sentence:";
    cin.getline(sentence,300);
    //loop for each character
    for(int i=0;i<strlen(sentence);i++) {
        //check & replase vowels : a e i o u  if((sentence[i]=='a')||(sentence[i]=='A'))  sentence[i]='$';
        else if((sentence[i]=='e')||(sentence[i]=='E'))  sentence[i]='@';
        else if((sentence[i]=='i')||(sentence[i]=='I'))  sentence[i]='#';
        else if((sentence[i]=='o')||(sentence[i]=='O'))  sentence[i]='&';
        else if((sentence[i]=='u')||(sentence[i]=='U'))  sentence[i]='%';
    }
    //display output after replacement
    cout<<"After replace the vowels:"<<sentence<<endl;
    return 0;
}

Electricity Charges (CPROM Uitm Arau 2015)

Rangkaian Tenaga charges electricity usage based on the following on the following table:

Usage(kWh per Month) Rates per kWh
For the first 250 kWh 0.10
For the next 200 kWh 0.20
For the next 200 kWh 0.30
For the next kWh above 650 kWh 0.50


The minimum monthly charge is RM 5.00 As a programmer, you are required to develop a system that calculate the electricity charges based on the above table.

Input : User is required to input the usage of electricity in kWh.
Output :The program will display the electricity charges.

InputOutput
26027
700150

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q2{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);
            
      int use = scan.nextInt();
      
      double total = 0;
      
      if(use<=250){
         total = use*0.10;
      }
      else if(use>250){
         total = 250*0.10;
         use = use - 250;
         
         if(use<=200){
            total = total + (use*0.2);
         }
         else if(use>200){
            total = total + (200*0.2);     
            use = use - 200;       
            if(use<=200){
               total = total + (use*0.3);   
            }
            else if(use > 200){
               total = total + (200*0.3);
               use = use - 200;
               total = total + (use*0.5);
            }   
         }
      }
      
      System.out.print(total);
   }
}


Judge Answers in C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <iostream>
using namespace std;
int main() {
    float kWh,charges;
    cin>>kWh;
    if(kWh<=50 ) charges=5.00;
    else if(kWh>50 && kWh<=250) charges=kWh*0.10;
    else if(kWh>250 && kWh<=450) charges=25+((kWh-250)*0.20);
    else if(kWh>450 && kWh<=650) charges=65+((kWh-450)*0.30);
    else charges=125+((kWh-650)*0.50);
    cout<<charges;
}