Dack problem

Revision en1, by shyamPrajapat, 2025-10-07 09:29:30

import java.util.* ; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in) ; int t = sc.nextInt() ; while( t --> 0){ int n = sc.nextInt() ; int k = sc.nextInt() ; String s = sc.next() ; int zero = 0 ; int one = 0 ; int two = 0 ; for(int i= 0 ; i < k ; i++){ int val = (int)s.charAt(i) — '0' ; if(val == 0)zero++ ; else if(val == 1)one++ ; else two++ ; } char ch[] = new char[n+1] ; for(int i = 1 ; i <= n ; i++){ ch[i] = '+' ; } if(two == n){ Arrays.fill(ch , '-') ; for(int i= 0 ; i < n ; i++)System.out.print(ch[i] + " ") ; System.out.println() ; continue ; }

for(int i = 1 ; i <= zero  ; i++){
            ch[i] = '-' ; 
        }
        for(int i = zero + 1 ; i <= zero + two ; i++){
            ch[i] = '?' ; 
        }
        for(int i =(n - (one + two)+1) ; i <= n - one ; i++){
            ch[i] = '?' ; 
        }
        for(int i = (n - one) + 1 ; i <= n ; i++){
            ch[i] = '-' ; 
        }
        for(int i = 1 ; i <= n ; i++){
            System.out.print(ch[i] +  " ") ; 
        }
        System.out.println() ; 
    }
}

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English shyamPrajapat 2025-10-07 09:29:30 1584 Initial revision (published)