Code: Select all
Cut After Accepted
Moderator: Board moderators
Code: Select all
Cut After Accepted
Code: Select all
Cut After Accepted
Code: Select all
don't
Code: Select all
don
t
Code: Select all
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
StringBuilder sb = new StringBuilder();
Set<String> orderedSet = new TreeSet<String>();
String s = br.readLine();
while (s != null)
{
s = s.toLowerCase();
String[] list = s.split(" ");
String word;
String w, sp;
boolean r = false;
for (int i = 0; i < list.length; i++) {
word = sp = "";
w = list[i];
for (int j = 0; j < list[i].length(); j++) {
if ((w.charAt(j) >= 'a' && w.charAt(j) <= 'z'))
{
r = true;
word += w.charAt(j);
}
else if(w.charAt(j) == '\'')
{
for (int k = ++j; k < list[i].length(); k++) {
sp += w.charAt(k);
}
orderedSet.add(sp);
break;
}
}
if(r)
orderedSet.add(word);
}
s = br.readLine();
}
for (String i: orderedSet) {
sb.append(i +"\n");
}
sb.deleteCharAt(sb.length()-1);
System.out.println(sb);
}
}
brianfry713 wrote:For an input file containing:My AC output is:Code: Select all
a\bc
I used the c function isalpha().Code: Select all
a bc
Code: Select all
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
StringBuilder sb = new StringBuilder();
Set<String> orderedSet = new TreeSet<String>();
String s = br.readLine();
String word;
String w, sp;
while (s != null)
{
s = s.toLowerCase();
String[] list = s.split(" ");
for (int i = 0; i < list.length; i++) {
word = ""; sp = "";
w = list[i];
boolean r1 = false;
boolean r2 = true;
for (int j = 0; j < w.length(); j++) {
if ((w.charAt(j) >= 'a' && w.charAt(j) <= 'z'))
{
r1 = true;
word += w.charAt(j);
}
else
{
for (int k = ++j; k < list[i].length(); k++) {
if ((w.charAt(j) >= 'a' && w.charAt(j) <= 'z'))
r2= false;
sp += w.charAt(k);
}
if(!r2)
orderedSet.add(sp);
break;
}
}
if(r1)
orderedSet.add(word);
}
s = br.readLine();
}
for (String i: orderedSet) {
sb.append(i +"\n");
}
sb.deleteCharAt(sb.length()-1);
System.out.println(sb);
}
}
again WA!!!!!!!!brianfry713 wrote:Try input:
a1b1c
Output should be:
a
b
c
Code: Select all
a\bc 1111111111x2222y1:""z,..,. e{g|f ThIsAWord222?#&*()!
andy's-->
~`cd()f:
;f^g9009?? /hijklmnop
q r s
<<<<<z>>>>>
9u)v(w**%x#y
Code: Select all
a
andy
bc
cd
e
f
g
hijklmnop
q
r
s
thisaword
u
v
w
x
y
z
Code: Select all
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#define pi acos(0)
#define inf 1<<30
#define max 10000
#define sz 5000
#define true 1
#define false 0
#define pb(a) push_back(a)
#define size(e) (int)e.size()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
using namespace std;
set <string> S;
int main()
{
char bin[sz];
string tmp;
while(gets(bin))
{
// getchar();
int strln = strlen(bin);
int i = 0;
for(int j = 0; j < strln; ++j)
bin[j] = tolower(bin[j]);
while(i < strln)
{
while(bin[i] >= 'a' && bin[i] <= 'z')
{
tmp.pb(bin[i]);
++i;
}
S.insert(tmp);
tmp.clear();
++i;
}
}
set <string> :: iterator sit;
for(sit = S.begin(); sit != S.end(); ++sit)
cout << *sit << endl;
return 0;
}