Răspuns :
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdlib.h>
using namespace std;
ifstream f("excel.in");
ofstream g("excel.out");
int suma[320][320][320];
int main()
{
char LxCy[20], numecel[255], *p;
int val, i, j, L, C, k, x, y, a, b, c, Lmax=-1, nr, L1, L2;
while(!f.eof())
{
f>>LxCy>>val;
p=strtok(LxCy,"LC");
L=atoi(p);
p=strtok(NULL,"LC");
C=atoi(p);
k=0;
numecel[0]='A';
numecel[1]='\0';
for(j=2;j<=C;j++)
{
if(numecel[k]<'Z')
numecel[k]++;
else{
bool schimbat=0;
for(x=k;x>=0;x--)
if(numecel[x]!='Z')
{
numecel[x]++;
schimbat=1; y=x;
break;
}
if(schimbat==0){
k++;
for(x=0;x<=k;x++)
numecel[x]='A';
numecel[k+1]='\0';
}
if(schimbat==1){
x=k;
while(numecel[x]=='Z' && y<x){
numecel[x]='A';
x--;
}
}
}
}
a=1; b=1; c=0;
for(i=1;i<=L;i++){
c++;
if(c==1000)
if(b==999){
a++; b=1; c=1;}
else{
b++; c=1;
}
}
suma[a][b][c]+=val;
g<<numecel<<L<<'\n';
if(Lmax<L)
Lmax=L;
}
nr=0;
for(i=1;i<=Lmax;i++){
a=1; b=1; c=0;
for(j=1;j<=i;j++){
c++;
if(c==1000)
if(b==999){
a++; b=1; c=1;
}
else{
b++; c=1;
}
}
if(suma[a][b][c]!=0)
{
if(nr!=0){
g<<nr<<' '<<0<<' '; nr=0;
}
g<<suma[a][b][c]<<' ';
}
else nr++;
}
return 0;
}