Sort by

recency

|

356 Discussions

|

  • + 0 comments
    import java.io.*;
    import java.util.*;
    import java.util.regex.*;;
    
    public class Solution {
    
        public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          while(sc.hasNext()) {
            int t = Integer.parseInt(sc.next());
            if(sc.hasNext(Pattern.compile("[0-9]+"))) {
              Integer[] ints = new Integer[t];
              for (int i = 0; i < t; i++) {
                ints[i] = sc.nextInt();
              }
              printArray(ints);
            } else {
              String[] strs = new String[t];
              for (int i = 0; i < t; i++) {
                strs[i] = sc.next();
              }
              printArray(strs);
            }
          }
          
          sc.close();
        }
        
        
        public static <T> void printArray(T[] array) {
          for (T t : array) {
            System.out.println(t);
          }
        }
    }
    
  • + 0 comments
    • class print{
    • public:
    • void print1(int arr[],int n){
    • for(int i=0;i
    • cout<
    • }
    • }
    • void print2(string arr1[],int n){
    • for(int i=0;i
    • cout<
    • }
    • }
      • };
      • int main() {
    • print p;
    • int n1,n2;
    • cin>>n1;
    • int arr[n1];
    • for(int i=0;i
    • cin>>arr[i];
    • }
    • cin>>n2;
    • string arr1[n2];
    • for(int i=0;i
    • cin>>arr1[i];
    • }
    • p.print1(arr,n1); p.print2(arr1,n2); type this in c++20 /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  • + 2 comments

    Why python is not available for this problem

  • + 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))
    }