Algorithm: Implement:
Code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<utility>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
vector<int> V;
map<int,int> M;
set<int> S;
int n,q;
string s;
string temp;
int l,r;
int di[11];
int cp,dp;
int current;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> n >> q;
cin >> s;
for(int i=0;i<q;i++)
{
cin >> l >> r;
for(int j=0;j<10;j++) di[j] = 0;
cp = 0;
dp = 1;
temp = string(s,l-1,r-l+1);
cout << "temp="<< temp<<endl;
while(true)
{
if(cp<0 || cp >= temp.size()) break;
if(temp[cp])
{
if(temp[cp]>='0' && temp[cp]<='9')
{
di[temp[cp]-'0']++;
temp[cp]--;
if(temp[cp]<'0') temp[cp]=0;
cp += dp;
}
else
{
if(temp[cp]=='<')
{
dp = -1;
}
else
{
dp = 1;
}
current = cp;
cp += dp;
if(cp<0 || cp>=temp.size())break;
while(temp[cp]==0)
{
cp += dp;
if(cp<0||cp>=temp.size())break;
}
if(temp[cp]=='<'||temp[cp]=='>') temp[current]=0;
}
}
else
{
cp += dp;
}
}
for(int j=0;j<10;j++) cout << di[j] << " ";
cout << endl;
//system("pause");
}
return 0;
}
Không có nhận xét nào:
Đăng nhận xét