为什么全爆REQAQ

P1042 [NOIP2003 普及组] 乒乓球

xuanmangguo @ 2024-10-03 15:28:04

#include<bits/stdc++.h>
using namespace std;
char c,str[100010];
int cnt=0;
int fen(int n) {
    int a,b;a=b=0;
    for(int i=0;i<cnt;i++) {
        if(str[i]=='W') a++;
        if(str[i]=='L') b++;
        if((a>=n||b>=n)&&abs(a-b)>=2) {
            cout<<a<<':'<<b<<endl;
            a=b=0;
        }
    }
    cout<<a<<":"<<b<<endl;
}
int main() {
    while(cin>>c&&c!='E') {
        if(c=='W'||c=='L') {
            str[cnt++]=c;
        }
    }
    fen(11);
    cout<<endl;
    fen(21);
    return 0;
}

by lzy120406 @ 2024-10-03 15:31:30

@xuanmangguo 返回值???


by lzy120406 @ 2024-10-03 15:32:04

@xuanmangguo fen是int类型


by xuanmangguo @ 2024-10-03 15:32:42

@lzy120406 ???不是啊,输出啊


by lzy120406 @ 2024-10-03 15:35:00

@xuanmangguo 你函数定义的是int,一定要有返回值


by lzy120406 @ 2024-10-03 15:35:33

@xuanmangguo 把int改成void


by xuanmangguo @ 2024-10-03 15:38:01

@lzy120406 好了谢谢


by xuanmangguo @ 2024-10-03 15:38:43

加个好友?


by lzy120406 @ 2024-10-03 15:40:20

@xuanmangguo ok


|