zoukankan      html  css  js  c++  java
  • 九度oj 题目1206:字符串连接

    题目1206:字符串连接

    时间限制:1 秒

    内存限制:128 兆

    特殊判题:

    提交:5117

    解决:2373

    题目描述:

    不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

    输入:

    每一行包括两个字符串,长度不超过100。

    输出:

    可能有多组测试数据,对于每组数据,
    不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
    输出连接后的字符串。

    样例输入:
    abc def
    样例输出:
    abcdef
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int StringLen(char *s){
     5     char *t = s;
     6     int len = 0;
     7     while(*t != ''){
     8         len++;
     9         t++;
    10     }
    11     return len;
    12 }
    13 
    14 char *StrCat(char *s1, char *s2){
    15     int len1 = StringLen(s1);
    16     int len2 = StringLen(s2);
    17     char *s = (char*)malloc((len1 + len2 + 1) * sizeof(char));
    18     char *t = s, *t1 = s1, *t2 =s2;
    19     while(*t1 != ''){
    20         *(t++) = *(t1++);
    21     }
    22     while(*t2 != ''){
    23         *(t++) = *(t2++);
    24     }
    25     *t = '';
    26     return s;
    27 }
    28 
    29 int main(){
    30     char s1[101], s2[101];
    31     while(scanf("%s %s", s1, s2) != EOF){
    32         printf("%s
    ", StrCat(s1, s2));
    33     }
    34     //system("pause");
    35     return 0;
    36 }
     
  • 相关阅读:
    firefox配置
    安装gstreamer开发环境
    linux下批量替换文件内容(转)
    iptables详细教程:基础、架构、清空规则、追加规则、应用实例(转)
    iptables 使用
    如何用iptables实现NAT(转)
    Python 练习题
    Python unittest 参数化
    Python Logging模块
    Python 多进程
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6496953.html
Copyright © 2011-2022 走看看