码迷,mamicode.com
首页 > 其他好文 > 详细

如何调试在OJ中的代码

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

标签:iostream   输入输出流   实例化   style   namespace   color   class   while   app   

在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中的代码

标签:iostream   输入输出流   实例化   style   namespace   color   class   while   app   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!