Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
cpp
main.cpp 2.9 kB 1 20-Aug-2015 17:35 filip_bujaroski Множење, Олимпијада

This page (revision-8) was last changed on 20-Aug-2015 17:35 by filip_bujaroski

This page was created on 20-Aug-2015 17:35 by bedzo

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 400 added 167 lines
!! Множење, Олимпијада
{{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;
int gol=0;
string mn(string a,string b)
{
string s;
int i,j,k;
vector<string> n,m;
k=b.size();
for(i=a.size()-1; i>=0; i--)
{
string tmp="0";
for(j=0;j<=b.size();j++)
tmp+='0';
for(j=b.size()-1; j>=0; j--)
{
int k=a[i]-48;
int q=b[j]-48;
k*=q;
tmp[j+1]+=(k%10);
tmp[j]+=(k/10);
while(tmp[j+1]>'9')
{
tmp[j+1]-=10;
tmp[j]++;
}
while(tmp[j]>'9')
{
tmp[j-1]++;
tmp[j]-=10;
}
}
string uber;
for(j=0; j<=k+3; j++)
uber+='0';
tmp=uber+tmp;
int size=tmp.size();
gol=max(gol,size);
while(tmp.size()<gol-1)
tmp+='0';
k--;
n.push_back(tmp);
}
s=n[0];
s.resize(gol*gol);
for(i=1; i<n.size(); i++)
{
string tmp=n[i];
for(j=n[i].size()-1; j>0; j--)
{
if(s[j]>'9')
{
s[j]-=10;
s[j-1]++;
}
s[j]+=tmp[j]-48;
if(s[j]>'9')
{
s[j]-=10;
s[j-1]++;
}
if(s[j-1]>'9')
{
s[j-2]++;
s[j-1]-=10;
}
}
}
// for(i=1;i<)
return s;
}
long long toint(string s)
{
int k=0;
int mn=1;
reverse(s.begin(),s.end());
int j=s.size()-1;
while(j>=0)
{
k+=s[j]-48;
k*=10;
j--;
}
k/=10;
return k;
}
int main()
{
int m;
m=0;
int i,j,k;
int niza[10];
vector<int> v;
for(i=1; i<=9; i++)
{
cin>>niza[i];
m+=niza[i];
}
for(i=1; i<=9; i++)
{
for(j=0; j<niza[i]; j++)
{
v.push_back(i);
}
}
reverse(v.begin(),v.end());
string prv,vtor;
prv+=v[0]+48;
for(i=1; i<v.size(); i++)
{
if(prv.size()<vtor.size())
{
prv+=v[i]+48;
}
else if(prv.size()>vtor.size())
{
vtor+=v[i]+48;
}
else
{
if(prv>vtor)
vtor+=v[i]+48;
else prv+=v[i]+48;
}
}
long long x=toint(prv);
x*=toint(vtor);
string s=mn(prv,vtor);
bool okej=false;
string res;
int to;
for(i=0;i<gol-1;i++)
{
if(s[i]!='0')
{
okej=true;
}if(okej)
cout<<s[i];
}
return 0;
}
}}}
-- Bujo
Version Date Modified Size Author Changes ... Change note
8 20-Aug-2015 17:35 9.808 kB filip_bujaroski to previous
7 20-Aug-2015 17:35 6.838 kB bedzo to previous | to last
6 20-Aug-2015 17:35 5.588 kB bedzo to previous | to last
5 20-Aug-2015 17:35 5.47 kB bedzo to previous | to last
4 20-Aug-2015 17:35 6.684 kB bedzo to previous | to last
3 20-Aug-2015 17:35 5.873 kB bedzo to previous | to last
2 20-Aug-2015 17:35 5.851 kB bedzo to previous | to last
1 20-Aug-2015 17:35 0.516 kB bedzo to last
« This page (revision-8) was last changed on 20-Aug-2015 17:35 by filip_bujaroski