好难啊 一直20

P1308 [NOIP2011 普及组] 统计单词数

```java import java.util.Scanner; public class Main{ static String word; static String pages; static int cnt; public static void solve() { int index = 0; int first = 0; int prmp = 0; while((index = pages.indexOf(word,prmp)) != -1) { if((pages.charAt(index + word.length()) == ' ' || pages.charAt(index + word.length()) == '\n') ) { if(index-word.length() <= 0 || pages.charAt(index-1) == ' ') { cnt++; if(cnt == 1) { first = index; } } } prmp = index+word.length(); } if(cnt != 0) { System.out.println(cnt + " " + first); }else { System.out.println(-1); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); word = sc.nextLine().toLowerCase(); pages = sc.nextLine().toLowerCase(); //System.out.println(pages.substring(403)); //System.out.println(pages); solve(); } } ``` 同样,刚刚做出来。提交了好多好多次。唉
by y1510049928 @ 2019-12-06 16:27:12


你你你......这是什么语言??~~java?c?~~
by xhQYm @ 2019-12-06 16:43:54


@[lixiaozhi](/user/296158) 你要全部换成大写或小写
by JasonZRY @ 2019-12-06 16:50:07


您好您的scanf只能输入一串到空格的字符后面的都读不进去呢Orz
by 李白莘莘学子 @ 2019-12-06 16:54:01


您可以getline(cin,Ari);
by 李白莘莘学子 @ 2019-12-06 16:54:54


|