zoukankan      html  css  js  c++  java
  • 如何调试在OJ中的代码

    在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 != ''){
                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 != ''){
                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;
    }
  • 相关阅读:
    php -- 魔术方法 之 对象输出 : __toString()
    php -- each()、list()
    php -- 魔术方法、魔术常量 简单介绍
    webbench
    md5sum/opensll md5
    shopt
    MD5
    print显示特定的数据格式
    gdb调试4--回退
    字符串化#、拼接字符##和可变参数宏(...和_ _VA_ARGS_ _)
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/6591814.html
Copyright © 2011-2022 走看看