xxxxxxxxxx
class Pair implements Comparable<Pair> {
public:
int wsf;
string psf;
Pair(int wsf, string psf){
this->wsf = wsf;
this->psf = psf;
}
int compareTo(Pair o){
return this->wsf - o->wsf;
}
}
xxxxxxxxxx
public class Jeep extends Vehicle{
public Jeep() {
}
public Jeep(String vehicleType, int enginePower, int technology, float price, float tax, int wheelCategory, String registrationNumber) {
super(vehicleType, enginePower, technology, price, tax, wheelCategory, registrationNumber);
}
@Override
public float getPrice() {
return (enginePower * 3500 * wheelCategory) + 1000 + (technology * 1000);
}
@Override
public float getTax() {
return (this.getPrice() * 0.2f) + 200;
}
}
xxxxxxxxxx
class I{
int i;
public void printNum(){
System.out.println(i);
}
}
class J extends I{
int j;
public void printNum(){
System.out.println(j);
}
}
class Ans{
public static void main(String[] args){
J a = new J();
a.i = 5;
a.j = 7;
a.j = a.i;
a.printNum();
}
}
xxxxxxxxxx
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j*j+" ");
}
System.out.println();
}
}
}
xxxxxxxxxx
// Client side implementation of UDP client-server model
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define PORT 8080
#define MAXLINE 1024
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from client";
struct sockaddr_in servaddr;
// Creating socket file descriptor
close(sockfd);
return 0;
}
xxxxxxxxxx
" + coded);
// decode it back
System.out.println(" Decoded: " + adfgvx.decode(coded));
//---------------------------------------------
// end of automatic tests
//---------------------------------------------
// now proceed with user input
Scanner scan = new Scanner(System.in);
System.out.print("\n Enter a Key: ");
String key = scan.nextLine();
Adfgvx user = new Adfgvx(key);
System.out.print("Enter a message: ");
String msg = scan.nextLine();
// dump the grid
user.dumpGrid();
System.out.println(" Key is: " + user.key);
System.out.println("Original: " + msg);
String cypher = user.encode(msg);
System.out.println(" Coded: " + cypher);
System.out.println(" Decoded: " + user.decode(cypher));
}
/**
* An internal class to hold the data (the character of each column)
* it implements comparable so the column could be sorted by alpahbetical order
*/
private class Column implements Comparable<Column> {
// the letter A D F G V X at the head of the column
private char header;
// all the letters in the column
private char[] letters;
// use when we cumulate the digits in the letters array
private int index;
/**
* Constructor that receives the letter as header
*/
Column(char header) {
this.header = header;
}
/**
* To set the number of elements in the column
*/
void setSize(int size) {
// build array to receive all elements
letters = new char[size];
// reset that we are at element 0
index = 0;
}
/**
* To return, while decoding, the number of characters to insert in the Column
*/
int getSize() {
return letters.length;
}
/**
* To add a letter to the column
*/
void add(char c) {
letters[index++] = c;
}
/**
* To get a single letter
*/
char getChar(int n) {
return letters[n];
}
/**
* To return as a String the letters in the column
*/
public String toString() {
return new String(letters);
}
/**
* To sort the columns by header
*/
public int compareTo(Column other) {
return header - other.header;
}
}
}
xxxxxxxxxx
System.out.println("Max Value:\t" + B[n][M]);
System.out.println("Selected Packs: ");
xxxxxxxxxx
public static int findMaximum(List<Integer> arr, int m) {
long l = 1 , r = (long)(1e9);
while(l<=r){
long mid = (l+r)/2;
if(!bool(arr , mid , m)) r = mid-1;
else l = mid+1;
}
return (int)r;
}
static boolean bool(List<Integer> arr , long dif , int m){
int prv = 0;
int c = 1;
for(int i = 1 ; i<arr.size() ; i++){
if(arr.get(i) - arr.get(prv) >= dif){
prv = i;
c++;
}
}
if(c>=m) return true;
return false;
}
xxxxxxxxxx
public static int findMaximum(List<Integer> arr, int m) {
long l = 1 , r = (long)(1e9);
while(l<=r){
long mid = (l+r)/2;
if(!bool(arr , mid , m)) r = mid-1;
else l = mid+1;
}
return (int)r;
}
static boolean bool(List<Integer> arr , long dif , int m){
int prv = 0;
int c = 1;
for(int i = 1 ; i<arr.size() ; i++){
if(arr.get(i) - arr.get(prv) >= dif){
prv = i;
c++;
}
}
if(c>=m) return true;
return false;
}
xxxxxxxxxx
public int rotatedWords(String input1, int input2) {
int c= 0;
String arr[] = input1.split(" ");
if (input1 != null && !input1.isEmpty()) {
for (int i = 0; i < arr.length; i++) {
String s1 = arr[i] + arr[i];
int start = arr[i].length() - input2;
System.out.println("arr[i] : " + arr[i]);
String s2 = s1.substring(start, start + arr[i].length());
System.out.println("s2 : " + s2);
if (s2.equalsIgnoreCase(arr[i])) {
count++;
}
}
}
return count;
}
xxxxxxxxxx
class Pair implements Comparable<Pair> {
public:
int wsf;
string psf;
Pair(int wsf, string psf){
this->wsf = wsf;
this->psf = psf;
}
int compareTo(Pair o){
return this->wsf - o->wsf;
}
}