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;
    }
  • 相关阅读:
    WinForm 自定义查询
    维护应用程序状态(三):使用用户配置文件
    解决无法获取 GridView 中BoundField 隐藏列值问题
    Nhibernate Unknown entity class 的解决办法
    GridView 18般绝技(转)
    IsPostBack介绍
    "ESLG.CommonUtility.NHibernateHelper"的类型初始值设定项引发异常
    Visible和style.display的不同
    维护应用程序状态(二):使用会话状态
    AS3与PHP通信的五种方法(基于HTTP协议)
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/6591814.html
Copyright © 2011-2022 走看看