1 条题解

  • 0
    @ 2025-4-12 22:06:17

    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:编写重载函数来打印字符串

    信息

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