ACM零起點2017-7-24(刷題)

來源:互聯網
上載者:User
題目來源:https://vjudge.net/

A - 條件陳述式和數組

讀入N名學生的成績,將獲得某一給定分數的學生人數輸出。 
Input測試輸入包含若干測試案例,每個測試案例的格式為 


第1行:N 
第2行:N名學生的成績,相鄰兩數字用一個空格間隔。 
第3行:給定分數 

當讀到N=0時輸入結束。其中N不超過1000,成績分數為(包含)0到100之間的一個整數。 
Output對每個測試案例,將獲得給定分數的學生人數輸出。 
Sample Input

380 60 9060285 660560 75 90 55 75750
Sample Output
102





AC代碼:

#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 - 簡單字串的讀寫  


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

The language is that peculiar as it has exactly one variable, called x. Also, there are two 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 is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

A programme in Bit++ is a sequence of statements, each of 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 are no empty statements. The operation and the variable can be written in any order. Output

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

1++X
Output
1
Input
2X++--X
Output
0



AC代碼:   #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 - 注意資料範圍  


Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

What is 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 has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be 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代碼:
#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 - 格式化輸入輸出  


還記得中學時候學過的楊輝三角嗎。具體的定義這裡不再描述,你可以參考以下的圖形: 
1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 
1 5 10 10 5 1 
Input輸入資料包含多個測試執行個體,每個測試執行個體的輸入只包含一個正整數n(1<=n<=30),表示將要輸出的楊輝三角的層數。 Output對應於每一個輸入,請輸出相應層數的楊輝三角,每一層的整數之間用一個空格隔開,每一個楊輝三角後面加一個空行。 Sample Input
2 3
Sample Output
11 111 11 2 1



AC代碼:(輸入格式要正確,不要在行末輸出多餘的空格)


#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;
}


E - 多組資料輸入輸出  

Your task is to Calculate a + b. 
Too easy?! Of course! I specially designed the problem for acm beginners. 
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim. 
InputThe input will 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 you should output the sum of a and b in one line, and with one line of output for each line in input. 
Sample Input
1 510 20
Sample Output
630




AC代碼:
#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 - 多個字串讀入  



對於給定的一個字串,統計其中數字字元出現的次數。 Input輸入資料有多行,第一行是一個整數n,表示測試執行個體的個數,後面跟著n行,每行包括一個由字母和數字組成的字串。 Output對於每個測試執行個體,輸出該串中數值的個數,每個輸出佔一行。 Sample Input
2asdfasdf123123asdfasdfasdf111111111asdfasdfasdf
Sample Output
69


AC代碼:
#include<cstdio>
#include<

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.