Click the Twitter icon to follow our tweets and
know more about us.

George And Accommodation

0

A. George and Accommodation

time limit per test-   1 second
memory limit per test-    256 megabytes
input-    standard input
output-   standard output
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
input
3
1 1
2 2
3 3
output
0
input
3
1 10
0 10
10 10
output
2
JAVA CODE

import java.io.*;
public class q1
{
 public static void main(String args[])throws IOException
 {
            int a=0,b,c;
   BufferedReader k=new BufferedReader(new InputStreamReader(System.in));
  int n=Integer.parseInt(k.readLine());
  for(int i=0;i<n;i++)
  {
   String nm[]=k.readLine().split(" ");
   c=Integer.parseInt(nm[0]);
   b=Integer.parseInt(nm[1]);
   a+=(b-c>1)?1:0;
  }
  System.out.println(a);
 }
}

The battle near the swamp

0

The battle near the swamp 

Time limit: 1 second 
Memory limit: 64 MB 
____________________________________________________________________________

Gungan: Jar Jar, usen da booma! 
Jar Jar: What? Mesa no have a booma! 
Gungan: Here. Taken dis one. 
_________________________________________________________________________________
In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed to provide their army in order to get the droids of the Federation out from the capital. The gungan ruler Boss Nass was so grateful for uniting the nations that he appointed Jar Jar a general. 

And here they are: two armies lined up along the bank of the swamp. The droids of the Federation are well-disciplined soldiers. They stand in neat formation, divided into 𝑛 blocks of 𝑘 droids each. The gungans have a foolproof weapon against droids, which is small energy balls called boom booms. One such ball can disable exactly one droid.

Jar Jar Binks also decided to split his army into 𝑛 parts and give each part a task to destroy the corresponding block of droids. Each part received a truck with boom booms. Now help general Binks calculate the number of boom booms that will be left unused and the number of droids that will survive the attack. You can assume that when a boom boom is fired at a droid by a gungan, it always hits the target. 

Input 
The first line of the input contains numbers 𝑛 and 𝑘 (1 ≤ 𝑛, 𝑘 ≤ 10 000). The second line contains 𝑛 numbers 𝑎𝑖 (0 ≤ 𝑎𝑖 ≤ 100 000) — the number of boom-booms in the 𝑖-th truck.

Output
Print two integers — the number of unused boom booms and the number of survived droids.


CODE in JAVA:

import java.io.*;

public class boomboom{
 public static void main(String []args)throws IOException{
  
  BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
   int[] j= new int[2],n;
   
    String[] s2 = inp.readLine().split(" ");
    j[0]=Integer.parseInt(s2[0]);
    j[1]=Integer.parseInt(s2[1]);
    
   
            int[] m= new int[j[0]];int c=0,k=0;
          
            String[] s1 = inp.readLine().split(" ");
           for(int i=0;i<j[0];i++)
              m[i]=Integer.parseInt(s1[i]);
            
            
            
            for(int l=0;l<j[0];l++){
             int a=j[1]-m[l];
             if(a>=0)
              k=k+a;
             else
              c=c-a;
             
            }
            System.out.println(c+"  "+k);
       }
       
       
    }
    

Books You Must Read

0
Click here to find yourselves amongst thousand of Books
Books are the ultimate source of knowledge. Oldest way of passing your knowledge to others and gaining knowledge from others. Till now they are not outdated. Look upon these books and choose the best suitable for you if you want to learn Java and practice here.
My personal favorite is Head First Java.

inc ARG

0

inc ARG

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit.
Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.
Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of bits in the cell.
The second line contains a string consisting of n characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.

Output
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
Examples
input
4
1100
output
3
input
4
1111
output
4
Note
In the first sample the cell ends up with value 0010, in the second sample — with 0000.

CODE in JAVA:

import java.io.*; 
import java.util.*; 
public class incarg{ 
    public static void main(String args[]) throws IOException {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
         int a = Integer.parseInt (br.readLine()),c=0; 
         String str = br.readLine();
         if(str.length()==a){
            for(int i=0;i<str.length();i++){
                char d = str.charAt(i);
                if(d == '1')
                    c++;
                else{
                    c++;
                    break;}
                }
                System.out.println(c);
            }
         }
    }

~Please leave your questions in the comments~


Way Too Long Words

0

Way Too Long Words


time limit per test :
2 seconds

memory limit per test : 
256 megabytes

input: 
standard input

output: 
standard output
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

Input
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Output
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
Examples
input
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
output
word
l10n
i18n
p43s
CODE in JAVA:
import java.io.*; 
import java.util.*; 
public class Watermelon{
 public static void main(String args[])throws IOException{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int n = Integer.parseInt(br.readLine());
 String word;
 for(int i=0; i<n; i++)
 { word = br.readLine();
  if(word.length() > 10){
  System.out.println(word.charAt(0)+""+(word.length()-2)+""+
                      word.charAt(word.length()-1));
  }
  else
   System.out.println(word);
 }
}
}

~Please leave your questions in the comments~