1 solutions

  • 0
    @ 2025-11-5 17:23:54

    C++ :

    #include<iostream>
    #include<string>
    #include<string.h>
    using namespace std;
    void print_spaced(char s[]){
    	int i;
    	while(s[i]!='\0'){
    		cout<<s[i];
    		if(i<strlen(s)-1){
    			cout<<' ';
    		}
    		i++;
    	}
    }
    void print_spaced(string s){
    	int i;
    	for(i=0;i<s.length();i++){
    		cout<<s[i];
    		if(i<s.length()-1){
    			cout<<' ';
    		}
    	}
    }
    main(){
    	char s1[101];
    	string s2;
    	cin.getline(s1,101);
    	cin>>s2;
    	print_spaced(s1);
    	cout<<endl;
    	print_spaced(s2);
    }
    

    Pascal :

    var s,st:string;
        i:longint;
    begin
      readln(s);
      readln(st);
      for i:=1 to length(s) do
      if i<>length(s) then write(s[i],' ')
      else write(s[i]);
      writeln;
      for i:=1 to length(st) do
      if i<>length(st) then write(st[i],' ')
      else write(st[i]);
    end.
    
    • 1

    C++字符串作业1:编写重载函数来打印字符串

    Information

    ID
    18383
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By