SPOJ 1163 — Java vs C++ (code: JAVAC)

Posted on 四月 21st, 2008.

挺水的题目,不过文字游戏有些多.题解没什么可写的.
给几组数据,自己拍去吧.

刚开始WA了N多次,结果把seekEoF改成EoF就AC了.

数据:

输入
n_e_e_r_c
JAVA
jAVA
n__e_r_c
bad_Style
Bad_style
java_
_another
long_and_mnemonic_identifier
anotherExample
c_identifier
n_e_e_r_c
n__e_r_c
nEER_c
i_iIi

输出
nEERC
Error!
j_a_v_a
Error!
Error!
Error!
Error!
Error!
longAndMnemonicIdentifier
another_example
cIdentifier
nEERC
Error!
Error!
Error!

附代码.

{
SPOJ 1163; Java vs C++; JAVAC
- sqybi’s code
}
//for my winsty
program javac_sqybi;
  var
    s, ss: string;
    ch: char;
    upper: array[’a’..’z']of char;
    lower: array[’A’..’Z']of char;
    f1, f2: boolean;
    i, n: longint;

  begin
    for ch:=’a’ to ‘z’ do begin
      upper[ch] := upcase(ch);
      lower[upcase(ch)] := ch;
    end;

    while not EoF do begin
      readln(s);
      n := length(s);
      if (s[1] < ‘a’) or (s[1] > ‘z’) then begin
        writeln(’Error!’);
        continue;
      end;
      if not (s[n] in [’a’..’z', ‘A’..’Z']) then begin
        writeln(’Error!’);
        continue;
      end;
      f1 := false;
      f2 := false;
      for i:=1 to n do
        if (s[i] >= ‘A’) and (s[i] <= ‘Z’) then begin
          f1 := true;
          if f2 then break;
        end
        else if s[i] = ‘_’ then begin
          f2 := true;
          if s[i-1] = ‘_’ then f1 := true;
          if f1 then break;
        end
        else if (s[i] < ‘a’) or (s[i] > ‘z’) then begin
          f1 := true;
          f2 := true;
          break;
        end;
      if f1 and f2 then begin
        writeln(’Error!’);
        continue;
      end;
      if f1 then begin
        ss := ”;
        for i:=1 to n do
          if (s[i] >= ‘a’) and (s[i] <= ‘z’) then
            ss := ss + s[i]
          else
            ss := ss + ‘_’ + lower[s[i]];
      end
      else begin
        ss := ”;
        for i:=1 to n do
          if (s[i] >= ‘a’) and (s[i] <= ‘z’) then
            if (i <> 1) and (s[i-1] = ‘_’) then
              ss := ss + upper[s[i]]
            else
              ss := ss + s[i];
      end;
      writeln(ss);
    end;
  end.

阅读(137 次)

Make a Comment

Make A Comment: ( None so far )

blockquote and a tags work here.

Liked it here?
Why not try sites on the blogroll...