首页 > 其他 > 详细

如何调试在OJ中的代码

时间:2017-03-20 22:21:39      阅读:245      评论:0      收藏:0      [点我收藏+]

在OJ上的原始程序:

class Solution {
public:
    void replaceSpace(char *str,int length) {if(str == NULL || length<=0)
            return;
        int length_origin = 0;
        int blank = 0;
        while(*str != \0){
            if(*str ==  ){
                blank++;
                length_origin++;
                str++;
            }
            else{
                length_origin++;
                str++;
                continue;
            }
        }int length_new = length_origin+2*blank;if(length_new > length)
            return;
        else{cout<<b<<endl;
            char *str_new = str+2*blank;while(str_new != str){
                if(*str ==  ){
                    *str_new = 0;
                    *(str_new-1) = 2;
                    *(str_new-2) = %;
                    str_new = str_new -3;
                    str--;
                }
                else{
                    *str_new =*str;
                    str_new--;
                    str--;
                }
            }
        }
    }
};

加入其他部分后的调试程序:

#include<iostream>                           标准输入输出流   
using namespace std;

class Solution {
public:
    void replaceSpace(char *str,int length) {
        cout<<a<<endl;
        if(str == NULL || length<=0)
            return;
        int length_origin = 0;
        int blank = 0;
        while(*str != \0){
            if(*str ==  ){
                blank++;
                length_origin++;
                str++;
            }
            else{
                length_origin++;
                str++;
                continue;
            }
        }int length_new = length_origin+2*blank;if(length_new > length)
            return;
        else{char *str_new = str+2*blank;while(str_new != str){
                if(*str ==  ){
                    *str_new = 0;
                    *(str_new-1) = 2;
                    *(str_new-2) = %;
                    str_new = str_new -3;
                    str--;
                }
                else{
                    *str_new =*str;
                    str_new--;
                    str--;
                }
            }
        }
    }
};
int main(){                                         c++运行main函数                               
    char str[] = "we are happy";
    Solution replace;                                   类Solution实例化了一个replce对象
    replace.replaceSpace(str,50);
    cout<<str<<endl;
    return 0;
}

 

如何调试在OJ中的代码

原文:http://www.cnblogs.com/ymjyqsx/p/6591814.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!