全WA求改

P1047 [NOIP2005 普及组] 校门外的树

Jer_here @ 2024-08-23 12:58:26

代码附上

#include <cstdio>
using namespace std;

unsigned short int l,m,u,v,ans=0;
bool a[15000];

int main(){
    scanf("%i %i",&l,&m);
    while(m--){
        scanf("%i %i",&u,&v);

        for(int i=u;i<=v;i++)   a[i]=1;
    }
    for(int i=0;i<=l;i++)   if(!a[i])   ans++;

    printf("%i\n",ans);
    return 0;
}

by meifan666 @ 2024-08-23 13:07:57

@meifan666 不是%d吗?


by pmkmzfuzsotqotmzs @ 2024-08-23 13:08:52

@Jer_here 用c++

#include <iostream>
using namespace std;

unsigned short int l,m,u,v,ans=0;
bool a[15000];

int main(){
    cin>>l>>m;
    while(m--){
        cin>>u>>v;

        for(int i=u;i<=v;i++)   a[i]=1;
    }
    for(int i=0;i<=l;i++)   if(!a[i])   ans++;

    cout<<ans<<endl;
    return 0;
}

by Jer_here @ 2024-08-23 13:12:53

@meifan666 改%d了,还是WA


by pmkmzfuzsotqotmzs @ 2024-08-23 13:20:41

@Jer_here 用%hu,因为你是unsigned short int,类型跟int不一样


by pmkmzfuzsotqotmzs @ 2024-08-23 13:22:32

#include <cstdio>
using namespace std;

unsigned short int l,m,u,v,ans=0;
bool a[15000];

int main(){
    scanf("%hu%hu",&l,&m);
    while(m--){
        scanf("%hu%hu",&u,&v);

        for(int i=u;i<=v;i++)   a[i]=1;
    }
    for(int i=0;i<=l;i++)   if(!a[i])   ans++;

    printf("%hu\n",ans);
    return 0;
}

by meifan666 @ 2024-08-23 13:28:20

@Jer_here 还是用cin吧,cin简单


|