6589 | 2023-12-12 17:05:36 | Huni136 | Zenehallgatás | cpp17 | Forditási hiba |
#include <iostream>
#include <map>
#include <vector>
using namespace std;
map<int,int> vlmi;
vector<int> a(100002,1e9);
int binkeres(int x, int kezd, int veg)
{
int kozep;
while(kezd<=veg)
{
kozep=(kezd+veg)/2;
if(a[kozep]>=x && a[kozep-1]<x)
{
return kozep;
}
else if(a[kozep]<x && a[kozep+1]>=x)
{
return kozep+1;
}
else if(x>a[kozep])
{
//return binkeres(x,kozep+1,veg);
kezd=kozep+1;
}
else
{
// return binkeres(x,kezd,kozep-1);
veg=kozep-1;
}
}
}
int main()#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
/*
Be:
3 2
2 4 3
6 10
KI:
2 1
*/
/*
Be:
5 3
3 2 7 8 1
10 50 20
Ki:
3 3 4
*/
/*
Be:
8 6
10 2 7 15 20 30 2 4
100 40 200 170 80 60
KI: 1 5 4 6 6 6
*/
int main()
{
int n,k;
cin>>n>>k;
vector<int> a(n), resz(n);
for(int i=0;i<n;i++)
{
cin>>a.at(i);
if (i==0)
resz.at(i)=a.at(i);
else
resz.at(i)=resz.at(i-1)+a.at(i);
}
/*
cout<<endl;
for(int x:resz)
cout<<x<<" ";
*/
int teljes=resz.at(n-1);
vector<int> kerdes(k), keresni(k);
//cout<<endl;
for(int i=0;i<k;i++)
{
cin>>kerdes.at(i);
keresni.at(i)=kerdes.at(i)%teljes;
}
/*cout<<endl;
for(int x:keresni)
cout<<x<<" ";
cout<<endl;
*/
for(int x:keresni)
{
int bal=0, jobb=n-1;
bool talalt=false;
while (bal<=jobb && !talalt)
{
//cout<<"bal "<<bal<<" jobb "<<jobb<<" *** ";
int kozepe=(bal+jobb)/2;
if(bal+1==jobb)
if(x<=resz.at(bal))
{
cout<<bal+1<<" ";
talalt=true;
}
else
{
cout<<jobb+1<<" ";
talalt=true;
}
else if(x<resz.at(kozepe))
jobb=kozepe;
else
bal=kozepe;
}
}
return 0;
}
{
int n,x,kdb;
cin>>n>>kdb;
//vector<int> a(n+1);
a[0]=0;
cin>>a[1];
for(int i=2;i<=n;i++)
{
cin>>x;
a[i]=a[i-1]+x;
//vlmi[prevveg]=i;
}
int k;
// auto seg=vlmi.end();
//prevveg++;
int hossz=a[n];
for(int i=1;i<=kdb;i++)
{
cin>>k;
k=k%(hossz);
if(k==0)
{
cout<<n<<" ";
continue;
}
if(k<a[1])
{
cout<<1<<" ";
}
else if(k>a[n-1])
{
//cout<<11111;
cout<<n<<" ";
}
else
{
cout<<binkeres(k,1,n)<<" ";
}
}
}
exit status 1
main.cpp:38:11: error: stray '#' in program
38 | int main()#include <iostream>
| ^
main.cpp:38:12: error: expected initializer before 'include'
38 | int main()#include <iostream>
| ^~~~~~~
main.cpp:142:1: error: expected unqualified-id before '{' token
142 | {
| ^
main.cpp: In function 'int binkeres(int, int, int)':
main.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
Exited with error status 1