1 条题解

  • 0
    @ 2025-12-5 16:55:34

    C :

    
    fanxu(str1)  
    char str1[100];  
    {int i,t,j;  
    char str2[100];strcpy(str2,str1);  
    t=strlen(str1);  
    for(i=0,j=t-1;j>-1;i++,j--)  
    str1[i]=str2[j];
    str1[i--]=0;
    }  
    
    int main()  
    {char str0[100];  
    scanf("%s",str0);  
    fanxu(str0);  
    printf("%s",str0);  
     return 0;
    }
    

    C++ :

    #include <iostream>
    //#include <stdio.h>
    //#include <conio.h>
    //#include <string>
    //#include <math.h>
    using namespace std;
    
    int main()
    {
    	char a[1000000];
    	int i = -1;
    	char buf;
    	for ( ; cin >> buf ; ) {
    		a[++i] = buf;
    		a[i+1] = '\0';
    	}
    	for ( ; i>=0 ; i--) {
    		cout << a[i];
    	}
    	//_getch();
    	return 0;
    }
    
    

    Java :

    import java.util.Scanner;
    import java.lang.StringBuilder;
    
    public class Main {
    
    
    	public static void main(String[] args) {
    		Scanner sca=new Scanner(System.in);
    		String str1=sca.next(); 	
    		String str2=reverse3(str1);
    		System.out.print(str2);
    
    	}
    	 public static String reverse3(String s) {
    		 
    		   char[] array = s.toCharArray();
    		 
    		   String reverse = "";
    		 
    		   for (int i = array.length - 1; i >= 0; i--)
    		 
    		    reverse += array[i];		   
    		 
    		   return reverse;
    		  }
    
    
    }
    
    

    Python :

    a = map(lambda x:(x), raw_input().split())[0]
    print a[-1:0:-1]+a[0]
    
    • 1

    C语言程序设计教程(第三版)课后习题8.5

    信息

    ID
    2015
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者