{
  "question_id": 769920,
  "question_title": "给出一个由O和X组成的串，长度为1~80，统计得分",
  "question_content": "给出一个由O和X组成的串，长度为1~80，统计得分，每个O的得分为目前连续出现的O的个数，X的得分为0，例如OOXXO的得分为1+2+0+0+1.",
  "difficulty": "简单",
  "answer_id": 831163,
  "answer_content": "//有一些小问题，改了一下\n#include\"stdlib.h\"\n#include\"string.h\"\n#include\"stdio.h\"\nint main()\n{\n\t\tchar s[85];\n    int score = 0,x;\n    scanf(\"%s\",&s);\n    for (int i = 0;s[i];i++)\n    {\n    \t\n        if (s[i] == 'X')\n\t\tscore += 0;\n        if (s[i] == 'O')\n        {\n            int temp = 1;\n            if (i == 0)score += 1;//这里要改为score+=1；否则当O处于第一个的时候会出统计错误问题\n            else\n            {\n            \tx=i;//主要问题在于循环查找O的时候外部‘i'与内部i发生冲突\n                while (x > 0)\n                {\n                    if (s[x - 1] == 'O')temp++;\n                    else break; \n                    x--;\n                }\n                score += temp;\n            }\n        }\n    }\n    printf(\"%d\\n\", score);\n\t\tsystem(\"pause\");\n    return 0;\n}",
  "tag_name": "c语言",
  "cpp": "#include\"stdlib.h\"\n#include\"string.h\"\n#include\"stdio.h\"\nint main()\n{\n\tchar s[85];\n\tint score = 0,x;\n\tscanf(\"%s\",&s);\n\tfor (int i = 0;s[i];i++)\n\t{\n\t\tif (s[i] == 'X')\n\t\tscore += 0;\n\t\tif (s[i] == 'O')\n\t\t{\n\t\t\tint temp = 1;\n\t\t\tif (i == 0)score += 1;\n\t\t\telse\n\t\t\t{\n\t\t\t\tx=i;\n\t\t\t\twhile (x > 0)\n\t\t\t\t{\n\t\t\t\t\tif (s[x - 1] == 'O')temp++;\n\t\t\t\t\telse break; \n\t\t\t\t\tx--;\n\t\t\t\t}\n\t\t\t\tscore += temp;\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"%d\\n\", score);\n\tsystem(\"pause\");\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600469970",
  "status": 1,
  "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/143.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "Harry_Kuma"
}