check strings are equal or not after concatenation of array of strings with other array of strings

Description

There is array of strings in first string and another string having array of strings.
Program is to concate first set of string and second set strings. Finally comapre
both the strings obatined after concatenation. Check both are equal or not.

Example 1 : String1 = {a,bc}
            String2 = {ab,c}
            Both strings are equal.
        
Example 2 :  String1 = {a,bc}
             String2 = {ac,b}
             Both Strings are not equal.

C/C++

/* C Program to check strings are equal or not after concatenation of array
 of strings with other array of strings */
//Save it as CompareStringsArrayOfStrings.c

#include<stdio.h>
int main(){

    int i, n1, n2;
    char str1[50][50];
    char str2[50][50];
    char newStr1[50]="";
    char newStr2[50]="";

    printf("Enter the size of first array of strings : ");
    scanf("%d",&n1);

    printf("Enter the strings in array of first strings : ");
    for(i=0;i<=n1;i++){
        gets(str1[i]);
        strcat(newStr1,str1[i]);
    }

    printf("Enter the size of second array of strings : ");
    scanf("%d",&n2);

    printf("Enter the strings in array of first strings : ");
    for(i=0;i<=n2;i++){
        gets(str2[i]);
        strcat(newStr2,str2[i]);
    }

    
    //printf("\nThe first string after append : %s",newStr1);
    //printf("\nThe second string after append : %s",newStr2);

    if(strcmp(newStr1,newStr2) == 0){
        printf("Both strings are equal after concatenation");
    }else{
        printf("Both strings are not equal after concatenation");
    }

    return 0;
}
Input:
Enter the size of first array of strings : 
2
Enter the strings in array of first strings : 
a
bc
Enter the size of second array of strings : 
2
Enter the strings in array of second strings : 
ac
b

Output:
Both strings are not equal after concatenation

Java

/* Java Program to check strings are equal or not after concatenation of array
 of strings with other array of strings */
//Save it as CompareStringsArrayOfStrings.java

import java.io.*;
import java.util.Scanner;
public class CompareStringsArrayOfStrings {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        
        System.out.println("Enter the size of first array of strings : ");
        int n1 = scanner.nextInt();
        
        String str1[] = new String[n1+1];
        String newStr1 = "";
        
        System.out.println("Enter the strings in array of first strings : ");
        for(int i=0;i<=n1;i++) {
            str1[i] = scanner.nextLine();
            newStr1 = newStr1.concat(str1[i]);
        }
        
        /*System.out.println("The all strings of first strings : ");
        for(int i=0;i<=n1;i++) {
            System.out.print(str1[i]+" ");
        }*/
        
        System.out.println("Enter the size of second array of strings : ");
        int n2 = scanner.nextInt();
        
        String str2[] = new String[n2+1];
        String newStr2 = "";
        
        System.out.println("Enter the strings in array of second strings : ");
        for(int i=0;i<=n2;i++) {
            str2[i] = scanner.nextLine();
            newStr2 = newStr2.concat(str2[i]);
        }
        
        /*System.out.println("The all strings of second strings : ");
        for(int i=0;i<=n2;i++) {
            System.out.print(str2[i]+" ");
        }*/
        
        
        //System.out.println("\nThe first string after concatenation : "+newStr1);
        //System.out.println("The second string after concatenation : "+newStr2);
        
        
        if(newStr1.equals(newStr2)) {
            System.out.println("Both strings are equal after concatenation");
        }else {
            System.out.println("Both strings are not equal after concatenation");
        }
    }
}
Input:
Enter the size of first array of strings : 
2
Enter the strings in array of first strings : 
a
bc
Enter the size of second array of strings : 
2
Enter the strings in array of second strings : 
ab
c

Output:
Both strings are equal after concatenation

Related programs

1) Program to remove vowels from a String
2) Program to Multiply Numbers Present in a String
3) Program to Add numbers present in a String
4) Program to remove given number from a string
5) Program to count Vowels, Consonants, Digits and Whitespaces
6) Count Number of Words in a String
7) Find Occurrence Of Each Word In a Sentence
8) Print All Unique Words Of A String
9) Program To Print Unique Word Of A String Using Set
10) Program to count uppercase and lowercase alphabet characters in String
11) Program to Sort set of strings in alphabetical order
Share Me

Leave a Reply