首页 > 代码库 > 学习笔记-动态规划-poj1050-修改中

学习笔记-动态规划-poj1050-修改中

////  main.c//  poj1050////  Created by 韩雪滢 on 10/13/16.//  Copyright © 2016 韩雪滢. All rights reserved.//#include <stdio.h>#include <stdlib.h>#define MAXLEN 10000/* poj1050 失败的小demo *其中包括 *读取一行字符串直到换行符 *将字符串按照空格拆分,将拆分的char[] 专为 int,正负整数 *用了一丢丢动态规划去求最大的值 *********************** *未实现的是  题目要求These are the N^2 integers of the array, presented in row-major order. That is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. 也就是说,是连续的 */int arraySize = 0;int max = 0;int getLine(char s[],int lim){    int c,i;    for(i = 0;i < lim-1 && (c=getchar()) != \n ;i++){        s[i] = c;    }        //如果for结束是因为换行符    if(c == \n){        s[i] = c;        ++i;    }        s[i] = \0;//字符串结束符    return i;//返回字符串的真实长度}void cutToInt(char s[],int rlen){    int i;    char sub[rlen];    int sublen = 0;    for(i=0;i<rlen+1;i++){                if(s[i] !=   && s[i] != \0){            sub[sublen] = s[i];            sublen++;        }else{            sub[sublen] = \0;                        int num;                        if(sub[0] == -){                char newSub[sublen-1];                int k;                for(k=0;k<sublen-2;k++)                {                    newSub[0] = sub[k+1];                }                newSub[sublen-2] = \0;                                num = (-1)*atoi(newSub);            }else{                num = atoi(sub);            }                                    max = (max > (max+num))?max:(max+num);                        arraySize++;                        //清空sub            int j;            for(j=0;j<sublen;j++){                sub[j] = \t;            }            sublen = 0;        }    }}int main() {        int n;    char c;    scanf("%d%c",&n,&c);        while(arraySize < n*n){                char line[MAXLEN];        int realLen = getLine(line, MAXLEN);                if(realLen > 0){            cutToInt(line, realLen);        }    }        printf("%d",max);        return 0;}

 

学习笔记-动态规划-poj1050-修改中