【记录一个奇奇怪怪的WA】Alignment of Code

踩坑

      简单来说,因为(对内存)抠门,我堵了半个多小时……即他数据最多1000行,你给他个1003行不行!真的,就是因为这种原因。

        (顺嘴,记得输出不要在每行末尾加空格哦~

AC代码

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>

//#define TEST//测试用

using namespace std;
const int max_n=1000+3;//就是你,浪费我时间啊!!

string words[max_n][180];
string line[max_n];
int cols[max_n][180];//一行中每个单词的长度
int max_col[180];//每列最大的单词长度
int max_words[max_n];//每行最大单词数

int main(){
//测试用,不懂自行百度
#ifdef TEST
    freopen("D:\\college\\clionworkplace\\test_c++\\in.txt","r",stdin);
    freopen("D:\\college\\clionworkplace\\test_c++\\out.txt","w",stdout);
#endif
    int i=0;
    memset(max_col,0,sizeof(max_col));
    while (getline(cin,line[i])){
        stringstream ss(line[i]);
        int j=0;
        while (ss>>words[i][j]){
            cols[i][j]=words[i][j].length();
            max_col[j]=max(max_col[j],cols[i][j]);//每一列最大的字符长度
            ++j;
        }
        max_words[i]=j;
        ++i;
    }
    for(int t1=0;t1<i;t1++){
        for(int t2=0;t2<max_words[t1];t2++){
            cout<<words[t1][t2];
            if(t2+1==max_words[t1]){
                break;
            }
            for(int t3=0;t3<max_col[t2]-cols[t1][t2]+1;t3++){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值