1. 程式人生 > >關於一些初級ACM競賽題目的分析和題解(一)。

關於一些初級ACM競賽題目的分析和題解(一)。

      關於一些初級ACM競賽題目的分析和題解(一)

  故事發生在在2017年年底,受我的室友cy1999巨巨的影響下,第一次接觸到ACM競賽,也是作為一名程式設計小白,第一次感受到程式語言的魅力。用競賽這種形式來提高自己的程式設計能力,雖說不上是曲徑通幽,但也不失為一種好方法。廢話少說,上題。 A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7

 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.

Input

The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100

 characters. There's at least one player from each team present on the field.

Output

Print "YES" if the situation is dangerous. Otherwise, print "NO".

Examples input
001001
output
NO
input
1000000001
output
YES
題目簡單易懂,輸入一行n個只包含0,1的數字串(n<100),若其中有連著7個0,或7個1,則輸出YES,否則輸出NO,
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;     //以上是打競賽題的套路
int main()
{
    char a[101];          //定義字串
    gets (a);             //陣列的輸入
    puts(strstr(a,"0000000")||strstr(a,"1111111")?"YES":"NO");  //陣列的輸出,且strstr(a,b)判斷b是否為a的子集
}
A. Next Round time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output

"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.

A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space.

The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).

Output

Output the number of participants who advance to the next round.

Examples input
8 5
10 9 8 7 7 7 5 5
output
6
input
4 2
0 0 0 0
output
0
Note

In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.

In the second example nobody got a positive score.

這個題目是輸入n,k,(1 ≤ k ≤ n ≤ 50第二行輸入n個數字(0 ≤ ai ≤ 100),且遞減 輸出有多少個數 大於等於第k個數,以下是程式碼

#include<bits/stdc++.h>
using namespace std;
int n,k,c,b,a[57];
int main()
{
    cin>>n>>k;
    while (n>b)

    cin>>a[b++];    //  輸入陣列
    while (a[c]&&a[c]>=a[k-1]) // a[c]不等於0且a[c]大於等於a[k-1]
        c++;
    cout<<c;  //輸出c
}