MISPELL 틀린 부분을 모르겠어요

  • merkunevus
    merkunevus

    입력 :
    The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.
    Each dataset consists of a single line of input containing M, a space, and a single word made up of uppercase letters only. M will be less than or equal to the length of the word. The length of the word is guaranteed to be less than or equal to 80.

    출력 :
    For each dataset, you should generate one line of output with the following values: The dataset
    number as a decimal integer (start counting at one), a space, and the misspelled word. The
    misspelled word is the input word with the indicated character deleted.

    일단 스캐너로 입력할 개수를 받고,
    개수만큼 for문을 돌려 각 줄을 입력받음.
    입력받은 문자열 중에 소문자가 있는지 체크하고 없으면
    문자열 길이 체크, m의 범위 체크한 뒤
    Dataset 을 만들어 저장하고, 마지막에 출력
    이렇게 만들었는데요, 여러단어들로 테스트 해보니 잘 되는데
    계속 채점에서 틀렸다고 뜨네요...
    어디가 문제인지 감이 안오네요;

    import java.util.ArrayList;
    import java.util.Scanner;

    public class Main {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        ArrayList<Dataset> set=new ArrayList<Dataset>();
        Dataset d;
        int n=sc.nextInt();sc.nextLine();
    
        if(n>=1&&n<=1000){
    
            for(int i=0;i<n;i++){
                String st=sc.nextLine();
                char[] ch=st.toCharArray();
                boolean upperChk=true;
    
                for(int j=0;j<ch.length;j++){
                    if(!(ch[j]>='a'&&ch[j]<='z')) {upperChk=true;}
                    else {upperChk=false; break;}
                }
    
                if(st.length()<=80&&upperChk==true){
                    Scanner sc2=new Scanner(st).useDelimiter("\\s");
                    int m=sc2.nextInt();
                    st=sc2.next();
                    if(m<=st.length()&&m!=0)
                        set.add(new Dataset(m,st)); 
                }
    
            }
    
        }
    
        for(int i=0;i<set.size();i++){
            d=set.get(i);
            String st1=d.st.substring(0,d.m-1);
            String st2=d.st.substring(d.m);
            System.out.println((i+1)+" "+d.st.substring(0, d.m-1)+d.st.substring(d.m));
        }
    
    }

    }

    class Dataset{

    int m=0;
    String st="";
    
    public Dataset(){}
    
    public Dataset(int m,String st){
        this.m=m;
        this.st=st;
    }

    }


    9년 전
1개의 댓글이 있습니다.
  • JongMan
    JongMan

    길이가 80인 문자열을 테스트로 한번 넣어보세요.

    그리고 앞으로 소스코드를 붙여넣으실 때는 구문강조를 사용해 주시기 바랍니다~


    9년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.