最后一个点错误之谜?

这题有坑吧?!
最后一个点WA了,其他全AC。。。
求大神来看看
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char ch,a[1000001];
int n,w11,l11,w21,l21;
int main()
{
while(scanf("%c",&ch) && ch!='E') a[n++]=ch;
if(n==0)
{
puts("0:0");
puts("");
puts("0:0");
return 0;
}
for(int i=0;i<n;i++)
{
if(w11 >= 11)
{
if( abs(w11-l11) >=2)
{
printf("%d:%d\n",w11,l11);
w11=0;
l11=0;
}
}
if(l11 >= 11)
{
if( abs(w11-l11) >=2)
{
printf("%d:%d\n",w11,l11);
w11=0;
l11=0;
}
}
if(a[i]=='W') w11++;
else if(a[i]=='L') l11++;
}
printf("%d:%d\n\n",w11,l11);
if(n==1) puts("0:0");
for(int i=0;i<n;i++)
{
if(w21 >= 21)
{
if( abs(w21-l21) >=2)
{
printf("%d:%d\n",w21,l21);
w21=0;
l21=0;
}
}
if(l21 >= 21)
{
if( abs(w21-l21) >=2)
{
printf("%d:%d\n",w21,l21);
w21=0;
l21=0;
}
}
if(a[i]=='W') w21++;
else if(a[i]=='L') l21++;
}
printf("%d:%d\n\n",w21,l21);
if(n==1) puts("0:0");
}

6 条评论

  • @ 2018-03-11 16:52:27

    C++实现:

    #include <iostream>
    #include <string>
    using std::string;
    void processing(string, int);
    int main(void)
    {
        using std::cin;
        using std::cout;
        using std::endl;
        bool run;
        int i;
        string result, winAndLose;
        run = true;
        while (run)
        {
            getline(cin, winAndLose);
            int len = int(winAndLose.length());
            if(len > 20) {
                len = 20;
            }
            for (i = 0; i < len; i++)
            {
                switch (winAndLose.at(i))
                {
                    case '\0':
                        run = false;
                        i = int(winAndLose.length());
                        break;
                    case 'E':
                        run = false;
                        i = int(winAndLose.length());
                        break;
                    case 'W':
                        result += winAndLose.at(i);
                        break;
                    case 'L':
                        result += winAndLose.at(i);
                        break;
                    default:
                        break;
                }
            }
        }
        processing(result, 11);
        cout << endl;
        processing(result, 21);
        return 0;
    }
    void processing(string winOrLose, int winScore)
    {
        using std::cout;
        using std::endl;
        int huaWin, huaLose, i;
        huaLose = 0;
        huaWin = 0;
        for(i = 0; i < int(winOrLose.length()); i++)
        {
            if ('W' == winOrLose.at(i))
            {
                huaWin++;
            }
            else if ('L' == winOrLose.at(i))
            {
                huaLose++;
            }
            if (((huaLose >= winScore) || (huaWin >= winScore)) && ((huaLose - huaWin > 1) || (huaWin - huaLose > 1)))
            {
                cout << huaWin << ":" << huaLose << endl;
                huaLose = 0;
                huaWin = 0;
            }
        }
        cout << huaWin << ":" << huaLose << endl;
        return;
    }
    
  • @ 2016-09-02 19:11:11

    @lrj124 您的代码我在其他网站看过,只求有谁能改我的代码

  • @ 2016-09-02 14:11:43
    #include <algorithm>
    #include <iostream>
    #include <map>
    using namespace std;
    //ifstream cin("table.in",ios :: in);
    //ofstream cout("table.out",ios :: out);
    int main() {
      ios :: sync_with_stdio(false);
      char ch;
      map <char,int> cnt11,cnt21;
      int tmp = 0,t[100001][2];
      while (cin >> ch) {
        if (ch == 'E') break;
        if (ch != '\n') {
          cnt11[ch]++;
          cnt21[ch]++;
        }
        if ((cnt11['W'] >= 11 || cnt11['L'] >= 11) && abs(cnt11['W']-cnt11['L']) >= 2) {
          cout << cnt11['W'] << ':' << cnt11['L'] << '\n';
          cnt11['W'] = 0;
          cnt11['L'] = 0;
        }
        if ((cnt21['W'] >= 21 || cnt21['L'] >= 21) && abs(cnt21['W']-cnt21['L']) >= 2) {
          t[++tmp][1] = cnt21['W'];
          t[tmp][2] = cnt21['L'];
          cnt21['W'] = 0;
          cnt21['L'] = 0;
        }
      }
      cout << cnt11['W'] << ':' << cnt11['L'] << "\n\n";
      for (int i = 1;i <= tmp;i++) cout << t[i][1] << ':' << t[i][2] << '\n';
      cout << cnt21['W'] << ':' << cnt21['L'];
      return 0;
    }
    
  • @ 2016-09-01 21:40:38

    看不懂pascal,有没有人纠正我的c++代码
    求大神

  • @ 2016-09-01 19:27:23

    @ysm 这是pascal的
    pascal
    var
    a,b:ansistring;
    c:char;
    i,w,l,n:longint;
    begin
    while c<>'E' do
    begin
    read(c);
    if c='W'
    then
    begin
    a:=a+c;
    w:=w+1;
    end;
    if c='L'
    then
    begin
    a:=a+c;
    l:=l+1;
    end;
    if ((w>=11) or (l>=11)) and (abs(w-l)>=2)
    then
    begin
    writeln(w,':',l);
    w:=0;
    l:=0;
    end;
    end;
    writeln(w,':',l);
    writeln;
    w:=0;
    l:=0;
    for i:=1 to length(a) do
    begin
    if a[i]='W'
    then
    w:=w+1;
    if a[i]='L'
    then
    l:=l+1;
    if ((w>=21) or (l>=21)) and (abs(w-l)>=2)
    then
    begin
    writeln(w,':',l);
    w:=0;
    l:=0;
    end;
    end;
    writeln(w,':',l);
    readln;
    end.

  • @ 2016-08-31 21:58:46

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 1536 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 1532 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 1532 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 1532 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 1532 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 1532 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 1532 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 1536 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 1540 KiB, score = 10
    测试数据 #9: WrongAnswer, time = 0 ms, mem = 1536 KiB, score = 0
    WrongAnswer, time = 45 ms, mem = 1540 KiB, score = 90

    • @ 2017-12-29 20:45:16

      我也是,我先都不知道哪有问题

  • 1

信息

ID
1217
难度
7
分类
字符串 点击显示
标签
递交数
18613
已通过
4247
通过率
23%
被复制
33
上传者