1 solutions

  • 0
    @ 2024-12-20 22:52:18

    C :

    #include<stdio.h>
    
    int N;
    
    char str[1005];
    
    int main()
    {
    	while(scanf("%d%*c",&N)==1) while(N--)
    	{
    		gets(str);
    		int i=0;
    		while(str[i])
    		{
    			while(str[i]==' ') { printf("%c",str[i++]); }
    			int WordLeft=i;
    			while(str[i]&&str[i]!=' ') { ++i; }
    			int WordRight=i-1;
    			while(WordLeft<=WordRight) { printf("%c",str[WordRight--]); }
    		}
    		printf("\n");
    	}
    	return 0;
    }
    

    C++ :

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
    	int n,i,j;
    	char a[1001],b[1001];
    	scanf("%d%*c",&n);
    	while(n--)
    	{
    		gets(a);
    		for(i=j=0;a[i]!='\0';i++,j++)
    		{
    			b[j]=a[i];
    			if(a[i]==' ')
    			{
    				b[j]='\0';
    				reverse(b,b+strlen(b));
    				printf("%s",b);
    				printf(" ");
    				j=-1;
    			}
    		}
    		b[j]=a[i];
    		reverse(b,b+strlen(b));
    		printf("%s\n",b);
    	}
    	return 0;
    }
    

    Pascal :

    program p1048;
    var st,s:ansistring;
        i,j,k,t:longint;
    begin
      readln(t);
      for i:=1 to t do
      begin
        readln(st);
        k:=pos(' ',st);
        while k<>0 do
        begin
          s:=copy(st,1,k-1);
          for j:=length(s) downto 1 do
           write(s[j]);
          write(' ');
          delete(st,1,k);
          k:=pos(' ',st);
        end;
        for j:=length(st) downto 1 do
         write(st[j]);
        writeln;
      end;
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		int t = Integer.parseInt(in.nextLine());
    		while(t-->0){
    			String s = in.nextLine();
    			String[] ss = s.split(" ");
    			StringBuffer sb = new StringBuffer();
    			for(int i=0;i<ss.length;i++){
    				StringBuffer tem = new StringBuffer(ss[i]);
    				tem.reverse();
    				sb.append(" ").append(tem);
    			}
    			System.out.println(sb.toString().substring(1));
    		}
    	}
    
    }
    
    

    C# :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace _1048
    {
        class Program
        {
            static void Main(string[] args)
            {
                string input;
                while ((input = Console.ReadLine())!=null)
                {
                    int n = Convert.ToInt32(input);
                    while ((n--) != 0)
                    {
                        string temp = Console.ReadLine();
                        string[] data = new string[1000];
                        data = temp.Split(' ');
                        int i;
                        int len = data.Length;
                        char[] result = new char[100];
                        bool flag = true;
                        for(i=0;i<len;i++)
                        {
                            result=data[i].ToCharArray();
                            Array.Reverse(result);
                            if (flag)
                            {
                                Console.Write(result);
                                flag = false;
                            }
                            else
                            {
                                Console.Write(' ');
                                Console.Write(result);
                            }
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
    }
    
    
    • 1

    Information

    ID
    787
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    9
    Tags
    # Submissions
    21
    Accepted
    3
    Uploaded By