{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "b156f0a0d59d4e3da115cc80043ef958",
  "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配",
  "title": "单词反转",
  "desc": [
    {
      "content": "\n随便输出一个字符串\nString str =\"45abc,+de==fg\";\n里面含有 abc，de，fg 三个单词\n怎么处理能让单词反转，其他顺序不变呢\n输出 “45cba,+ed==gf”;",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "public class HelloWorld {\n\tpublic static String revstr(String s) {\n\t\tchar[] ch = s.toCharArray();\n\t\tfor (int i = 0; i < ch.length; i++) {\n\t\t\tif ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')) {\n\t\t\t\tint j = i + 1;\n\t\t\t\twhile (j < ch.length && ((ch[j] >= 'A' && ch[j] <= 'Z') || (ch[j] >= 'a' && ch[j] <= 'z')))\n\t\t\t\t\tj++;\n\t\t\t\tj--;\n\t\t\t\tif (i != j) {\n\t\t\t\t\tfor (int k = i; k <= (j - i) / 2 + i; k++) {\n\t\t\t\t\t\tchar temp = ch[k];\n\t\t\t\t\t\tch[k] = ch[j - k + i];\n\t\t\t\t\t\tch[j - k + i] = temp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti = j;\n\t\t\t}\n\t\t}\n\t\treturn new String(ch);\n\t}\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(revstr(\"45abc,+de==fg\"));\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-adbef0040dc440618bed1f48bef2c16c",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600469879"
}