ACM 0 Beginnings 2017-7-24 (brush question)

Source: Internet
Author: User
Tags integer integer numbers printf
Title Source: https://vjudge.net/

A-Conditional statements and Arrays

reading the scores of n students, the number of students will be output for a given score.
The input test inputs contain several test cases, each of which is in the format


Line 1th: N
Line 2nd: The results of n students, two adjacent numbers with a space interval.
Line 3rd: given score

The input ends when the n=0 is read. where n is not more than 1000, the score is (contains) an integer between 0 and 100.
Output for each test case, the number of students for a given score is outputted.
Sample Input

3-
2-
0
5 (
0)
Sample Output
1
0
2





AC Code:

#include <cstdio>

int a[1005];

int main ()
{
    int n;
    while (scanf ("%d", &n) && N)
    {
        int score;
        int num=0;
        for (int i=0;i<n;i++)
            scanf ("%d", &a[i]);
        scanf ("%d", &score);
        for (int i=0;i<n;i++)
            if (a[i]==score)
                num++;
        printf ("%d\n", num);
    }
    return 0;
}
B-Reading and writing of simple strings


The classic programming language of Bitland is bit++. This language was so peculiar and complicated.

The language is this peculiar as it has exactly one variable, called X. Also, there is both operations:operation + + increases the value of variable x by 1. Operation-decreases the value of variable x by 1.

A statement in language bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that's, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

A programme in bit++ are a sequence of statements, each of the them needs to be executed. Executing a programme means executing all the statements it contains.

You ' re given a programme in language bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input

The first line contains a single integer n (1≤n≤150)-the number of statements in the programme.

Next n lines contain a statement each. Each statement contains exactly one operation (+ + or-) and exactly one variable x (denoted as letter«x»). Thus, there is no empty statements. The operation and the variable can be written on any order. Output

Print a single integer-the final value of x. Example Input

1
++x
Output
1
Input
2
x + +
--x
Output
0



AC Code:#include <cstdio>
#include <cstring>


int main ()
{
int n;
int result=0;
Char str[10];
scanf ("%d", &n);
for (int i=0;i<n;i++)
{
scanf ("%s", str);
for (int j=0;j<strlen (str); j + +)
{
if (str[j]== ' + ')
{
result++;
Break
}
if (str[j]== '-')
{
result--;
Break
}
}
}
printf ("%d\n", result);
return 0;
}


C-note data range


Theatre Square in the Berland have a rectangular shape with the size nxm meters. On the occasion of the city ' s anniversary, a decision is taken to pave the square with square granite flagstones. Each flagstone is of the size AXA.

What's the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the theatre square, but the square have to be covered. It's not a allowed to break the flagstones. The sides of flagstones should is parallel to the sides of the Square. Input

The input contains three positive integer numbers in the first line:n, M and a (1≤n, M, a≤109). Output

Write the needed number of flagstones. Example Input

6 6 4
Output
4



AC Code:
#include <cstdio>


int main ()
{
Long Long n,m,a;
scanf ("%i64d%i64d%i64d", &n,&m,&a);
if (n%a==0) n=n/a;
else n=n/a+1;
if (m%a==0) m=m/a;
else m=m/a+1;
printf ("%i64d\n", m*n);
return 0;
}


D-formatted input and output


Remember the Yang Hui triangle you learned in high school? Specific definitions are no longer described here, you can refer to the following graphs:
1
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
1 5 10 10 5 1
Input data contains multiple test instances, and each test instance input contains only one positive integer n (1<=n<=30), representing the number of layers of the Yang Hui triangle that will be output. Output corresponds to each input, export the Yang Hui triangle of the corresponding number of layers, separated by a space between the integers of each layer, and a blank line behind each Yang Hui triangle. Sample Input
2 3
Sample Output
1
1 1

1
1 1
1 2 1



AC Code: (the input format should be correct, do not output extra space at the end of the line)


#include <cstdio>


int a[30][30];


int main ()
{
for (int i=0;i<30;i++)
{
A[i][0]=a[i][i]=1;
if (i>=2)
{
for (int j=1;j<i;j++)
A[I][J]=A[I-1][J]+A[I-1][J-1];
}
}
int n;
while (scanf ("%d", &n)!=eof)
{
for (int i=0;i<n;i++)
{
for (int j=0;j<=i;j++)
{
if (j==0) printf ("%d", a[i][j]);//Pay attention not to output extra spaces at the end of the line
else printf ("%d", a[i][j]);
}
printf ("\ n");
}
printf ("\ n");
}
return 0;
}


E-Multiple sets of data input and output

Your task is to Calculate A + B.
Too easy?! of course! I specially designed the problem for ACM beginners.
You must has found that some problems has the same titles with this one, yes, all these problems were designed for the s Ame aim.
Inputthe input would consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Outputfor each pair of input integers A and B are should output the sum of a and B in one line, and with one line of OUTPU T for each line in input.
Sample Input
1 5
10 20
Sample Output
6
30




AC Code:
#include <cstdio>


int a[30][30];


int main ()
{
for (int i=0;i<30;i++)
{
A[i][0]=a[i][i]=1;
if (i>=2)
{
for (int j=1;j<i;j++)
A[I][J]=A[I-1][J]+A[I-1][J-1];
}
}
int n;
while (scanf ("%d", &n)!=eof)
{
for (int i=0;i<n;i++)
{
for (int j=0;j<=i;j++)
{
if (j==0) printf ("%d", a[i][j]);
else printf ("%d", a[i][j]);
}
printf ("\ n");
}
printf ("\ n");
}
return 0;
}


F-Multiple strings read in



Counts the number of occurrences of a numeric character for a given string. Input data has multiple lines, the first line is an integer n, indicating the number of test instances, followed by n rows, each containing a string consisting of letters and numbers. Output for each test instance, outputs the number of values in the string, with each output occupying one row. Sample Input
2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf
Sample Output
6
9


AC Code:
#include <cstdio>
#include <

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.