Sort by

recency

|

353 Discussions

|

  • + 0 comments

    cpp

    One should take the input in this way

    int n; cin >> n; vector intVector(n); for (int i = 0; i < n; i++) { cin >> intVector[i]; }

    int s;
    cin >> s;
    vector<string> strVector(s);
    for (int i = 0; i < s; i++) {
        cin >> strVector[i];
    }
    
  • + 0 comments

    Typescript

    'use strict';
    
    process.stdin.resume();
    process.stdin.setEncoding('utf-8');
    let inputString: string = '';
    let inputLines: string[] = [];
    let currentLine: number = 0;
    process.stdin.on('data', function(inputStdin: string): void {
        inputString += inputStdin;
    });
    
    process.stdin.on('end', function(): void {
        inputLines = inputString.split('\n');
        inputString = '';
        main();
    });
    
    function readLine(): string {
        return inputLines[currentLine++];
    }
    
    function main() {
        // Enter your code here
        while (readLine()) {
            const previousValue = parseInt(inputLines[currentLine - 1])
            
            const arr = inputLines.slice(currentLine, currentLine + previousValue)
            
            printArray(arr)
    
            currentLine += previousValue
        }
    }
    
    function printArray<T>(arr: Array<T>) {
        arr.forEach(item => console.log(item))
    }
    
  • + 0 comments

    public void printArray(T[] list){ for(T type: list){ System.out.println(type); }

    }
    
  • + 0 comments
    The problem is not properly explained but the Input format is like this:
    3 -- count -> 1, 2, 3
    1
    2
    3
    2 -- count -> Hello, World
    Hello
    World
    
  • + 0 comments

    in TS

    function printArray<T>(arr: T[]) {
        arr.forEach(i => console.log(i))
    }