选择题
编程题
题目1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char[] c = s.toCharArray();
int i = 0;
int t = 0;
while (i < c.length) {
if (c[i] != '\"') {
while (i < c.length && c[i] != ' ') {
// System.out.print(c[i]);
i++;
}
i++;
// System.out.println();
t++;
} else if (c[i] == '\"') {
i++;
while (i < c.length && c[i] != '\"') {
// System.out.print(c[i]);
i++;
}
i += 2;
// System.out.println();
t++;
}
}
System.out.println(t);
i = 0;
while (i < c.length) {
if (c[i] != '\"') {
while (i < c.length && c[i] != ' ') {
System.out.print(c[i]);
i++;
}
i++;
System.out.println();
t++;
} else if (c[i] == '\"') {
i++;
while (i < c.length && c[i] != '\"') {
System.out.print(c[i]);
i++;
}
i += 2;
System.out.println();
t++;
}
}
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
char[] c = s.toCharArray();
int i = 0;
int t = 0;
StringBuffer sb = new StringBuffer();
while(i<c.length) {
if(c[i]!='\"') {
while(i<c.length && c[i]!=' ') {
// System.out.print(c[i]);
sb.append(c[i]);
i++;
}
i++;
// System.out.println();
sb.append("1");
t++;
}else if(c[i] == '\"') {
i++;
while(i<c.length && c[i] != '\"') {
// System.out.print(c[i]);
sb.append(c[i]);
i++;
}
i+=2;
// System.out.println();
sb.append("1");
t++;
}
}
System.out.println(t);
for(i=0;i<sb.length();i++) {
if(sb.charAt(i)!='1')
System.out.print(sb.charAt(i));
else
System.out.println();
}
sc.close();
}
}