Algorithmic Learning--day3

Source: Internet
Author: User
Tags integer numbers

Today, the hash of a wave of algorithms, the code is not big, recorded here.

The title describes "SquarePants underwater"--a word we like to use when describing a friend. Two people are friends usually means that they have a lot of common interests. As an otaku, however, you find that you don't have a lot of opportunities to get to know each other.     Fortunately, you accidentally got a book borrowing records from the Peking University Library, so you midnight oil to stay up late and program to find potential friends from it. First of all, you have a record of the borrowing records, the N readers sequentially numbered,..., N, the M book is numbered,..., m. At the same time, according to the "SquarePants underwater" principle, and the person you like to read the same book, is your potential friend. Your task now is to calculate from this borrowing record how many potential friends each person has. Input Description:
The first line of each case is two integers n,m,2 <= N, m<= 200. Next there are N rows, and the first (i =,..., N) row has a number that represents the reader I-1 's favorite book's number P (1<=p<=m)
Output Description:
Each case consists of n rows, one number per line, and the number of rows I indicates that reader I has several potential friends. If I and anyone do not have a common favorite book, then output "beiju" (i.e. tragedy, ^ ^)
Example 1 input
4  52321
Output
1beiju1beiju

#include<stdio.h>inthash[201];intMain () {intN;  while(SCANF ("%d", &n)! =EOF) {        intm; intsave_array[10000]; scanf ("%d",&m);  for(intI=0; i<n;i++) {scanf ("%d",&Save_array[i]); Hash[save_array[i]]++; }         for(intj=0; j<n;j++){            if(hash[save_array[j]]>1) printf ("%d\n", hash[save_array[j]]-1); Elseprintf"beiju\n"); }    }    return 0;}

The title described has a length of the whole number of L (1<=l<=10000) of the road, you can imagine the length of the axis of a line of L, the starting point is the origin of the coordinates, at each integer coordinate point there is a tree, that is, in 0,1,2,...,l a total of l+1 positions have l+1 tree.     Now to remove some trees, the interval of the removed tree is represented by a pair of numbers, such as 100 200 to remove all trees from 100 to 200 (including the endpoints). There may be an M (1<=m<=100) interval, and there may be overlapping between intervals. The number of trees remaining after the tree is now required to remove all intervals. Input Description:
Two integer L (1<=l<=10000) and M (1<=m<=100). Next there are M-group integers, each with a pair of numbers.
Output Description:
There may be multiple sets of input data, and for each set of input data, a number is output that represents the number of trees left after the tree has been removed from all intervals.
Example 1 input
500 3100 200150) 300470 471
Output
298

#include <stdio.h>#include<iostream>intMain () {intN;  while(SCANF ("%d", &n)! =EOF) {        intTimes ; inthash[10001]={1};  for(intz=0; z<=n;z++) {Hash[z]=1; } std::cin>>Times ;  for(inti =0; I < times; i++) {            intx, y; Std::cin>>x>>y;  for(intj = x; J <= y; J + +) {Hash[j]=0; }        }        intHi =0;  for(intz=0; z<=n;z++){            if(hash[z]==1) fin++; }std::cout<<fin<<Std::endl; }    return 0;}

The title describes you as given an unsorted array of integer numbers. Your task is to the sort this array and the kill possible duplicated elements occurring in it. Enter a description:
The first line of the input contains a integer number N representing the quantity of numbers in this array (1≤n≤1000). Next n lines contain n integer numbers (one number per line) of the original array.
Output Description:
For each case, the Outtput file should contain at the most N numbers sorted in ascending order. Every number in the output file should occur only once.
Example 1 input
68 8 7 3 7 7
Output
3 7 8

#include <algorithm>#include<stdio.h>BOOLcmpintAintb) {    returna<b;}intMain () {intN;  while(SCANF ("%d", &n)! =EOF) {        intarray[1001];  for(intI=0; i<n;i++) {scanf ("%d",&Array[i]); } std::sort (Array,array+n,cmp); printf ("%d", array[0]);  for(intI=1; i<n;i++){            if(array[i]!=array[i-1]) printf ("%d", Array[i]); if(i==n-1) printf ("\ n"); }    }    return 0;}

The title describes the number of students who read the scores of n students and will get the output of a given score. Input Description:
The test input contains several test cases, each of which is in the form of line 1th: n the 2nd row: N Students ' scores, with two adjacent digits separated by a space. Line 3rd: When a given fraction is read to n=0, the input ends. where n is not more than 1000, the score is (contains) an integer between 0 and 100.
Output Description:
For each test case, you will get the student number output for a given score.
Example 1 input
380 60 9060285 660560 75 90 55 75750
Output
102

#include <stdio.h>intMain () {intN;  while(SCANF ("%d", &n)!=eof&&n!=0){        inthash[101]={0};  for(intI=0; i<n;i++){            intx; scanf ("%d",&x); HASH[X]++; }        intA; scanf ("%d",&a); printf ("%d\n", Hash[a]); }    return 0;}

Algorithmic Learning--day3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.