[Codeforces]999A. Mishka and Contest

題目URL: http://codeforces.com/contest/999/problem/A
這題主要是判斷ai小就break,兩頭掃過去判斷一下順便記數,但記得特判全部都可以的時候


#include<bits/stdc++.h>
using namespace std;
int str[1005];
signed main()
{
    int a,num,total=0,key=0;
    cin >> num >> a;
    for(int i=1;i<=num;i++)
    {
        cin >> str[i];
        if(str[i]<=a && key==0)
        {
            total++;
        }
        if(str[i]>a)
            key=1;
    }
    if(total==num) return cout << num ,0;
    total=0;
    for(int i=1;i<=num;i++)
    {
        if(str[i]<=a)
            total++;
        else
            break;
    }
    for(int i=num;i>=1;i--)
    {
        if(str[i]<=a)
            total++;
        else
            break;
    }
    cout << total <<endl;
    return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP