Remove duplicates in a given elements?
Q) Write a program to remove duplicates in a given elements?
Sample Input:-
Enter elements separated by space :
2 3 4 2 2 2 2 2 2 2 1 1 2 3 1 2
Output:-
1 2 3 4
Python code:-
l=[]
print "Enter elements separated by space : "
l=map(int,raw_input().split())
l=list(set(l))
for i in range(len(l)):
print l[i],
Sample Input:-
Enter elements separated by space :
2 3 4 2 2 2 2 2 2 2 1 1 2 3 1 2
Output:-
1 2 3 4
Python code:-
l=[]
print "Enter elements separated by space : "
l=map(int,raw_input().split())
l=list(set(l))
for i in range(len(l)):
print l[i],
Count frequency of characters in string
Q) Write a program to count frequency of characters in given string?
Sample Input:--
Enter a string : python programming
Output:-
a 1
g 2
h 1
i 1
m 2
n 2
o 2
p 2
r 2
t 1
y 1
python code:-
s=raw_input("Enter a stirng : ")
al='abcdefghijklmnopqrstuvwxyz'
au='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l=[0]*26
m=[0]*26
for i in range(26):
l[i]=s.count(al[i])
m[i]=s.count(au[i])
for i in range(26):
if l[i]!=0:
print al[i],l[i]
if m[i]!=0:
print au[i],m[i]
Sample Input:--
Enter a string : python programming
Output:-
a 1
g 2
h 1
i 1
m 2
n 2
o 2
p 2
r 2
t 1
y 1
python code:-
s=raw_input("Enter a stirng : ")
al='abcdefghijklmnopqrstuvwxyz'
au='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l=[0]*26
m=[0]*26
for i in range(26):
l[i]=s.count(al[i])
m[i]=s.count(au[i])
for i in range(26):
if l[i]!=0:
print al[i],l[i]
if m[i]!=0:
print au[i],m[i]
Java Arithmetic Challange
Problem Statement
Welcome to Day 2!
Practice how to do arithmetic with code in this challenge! If given themeal price , tip percentage , and tax percentage , we can find the final price of a meal.
In many of these challenges, you will need to read input from stdin (standard input) and write your output in stdout (standard output). Different programming languages provide different ways to handle input and output.
In Java, one way to take input from stdin is to use theScanner class and read in from System.in . In other words, Java's Scanner class allows us to get information from the user/outside world by reading in from System.in.
In this problem, we read as input the original price of the meal, tip percentage, and tax percentage.
Good luck!
Practice how to do arithmetic with code in this challenge! If given the
In many of these challenges, you will need to read input from stdin (standard input) and write your output in stdout (standard output). Different programming languages provide different ways to handle input and output.
In Java, one way to take input from stdin is to use the
In this problem, we read as input the original price of the meal, tip percentage, and tax percentage.
Good luck!
Input Format
Three numbers, (M , T , and X ), each on separate lines:
M will be a double representing the original price of the meal.
T will be a integer representing the percentage that the customer wants to tip based off of the original price of the meal.
X will be an integer representing the tax percentage that the customer has to pay based off of the original price of the meal.
Output Format
A string stating...The final price of the meal is $-.
Where the final price of the meal is substituted for the dash.
The price should be rounded to the nearest integer (doller) -
the code for rounding has already been added in the editor if you are coding in java.
Sample Input
12.00
20
8
12.00
20
8
Sample Output
The final price of the is meal is $15.
The final price of the is meal is $15.
Explanation
tip=
tax=
final price=
Officially, the price of the meal is
Java Code:-
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Arithmetic {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double M = sc.nextDouble(); // original meal price
int T = sc.nextInt(); // tip percentage
int X = sc.nextInt(); // tax percentage
double tip=(T*M)/100;
double tax=(X*M)/100;
int total = (int) Math.round(M+tip+tax);
System.out.println("The final price of the meal is $"+total+".");
}
}
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Arithmetic {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double M = sc.nextDouble(); // original meal price
int T = sc.nextInt(); // tip percentage
int X = sc.nextInt(); // tax percentage
double tip=(T*M)/100;
double tax=(X*M)/100;
int total = (int) Math.round(M+tip+tax);
System.out.println("The final price of the meal is $"+total+".");
}
}
Subscribe to:
Posts (Atom)