#include <iostream> #include <vector> using namespace std;   int getRes(vector<char> &arr, int l, int r) {     if(l > r) return 0;     if(l == r && arr[l-1] != '<' && arr[l-1] != '>') return arr[l-1] - '0';     vector<char> tem;     for(int i=l-1; i<r; i++)         tem.push_back(arr[i]);     int flag = 1;     int ind = 0, len = r - l + 1, res = 0;     while(ind >= 0 && ind < len) {         if(tem[ind] == '<') {             if(ind-1 >= 0 && tem[ind-1] == '<' || tem[ind-1] == '>')                 len--, tem.erase(tem.begin() + ind);             ind--, flag = -1;         } else if(tem[ind] == '>') {             if(ind+1 < len && tem[ind+1] == '<' || tem[ind+1] == '>')                 len--, tem.erase(tem.begin() + ind),ind--;             ind++, flag = 1;         } else {             res += tem[ind] - '0';             if(tem[ind] == '0')                 len--, tem.erase(tem.begin() + ind);             else tem[ind]--;             ind += flag;         }         //for(auto &it:tem) cout<< it<< ' '; cout << endl;     }     return res; }   int main() {     int n, m, q, l, r;     cin >> n >> m >> q;     vector<char> arr(n);     for(int i=0; i<n; i++)         cin >> arr[i];     for(int i=0; i<q; i++) {         cin >> l >> r;         int res = getRes(arr, l, r);         cout << res << endl;     }     return 0; }
点赞 1

相关推荐

03-21 08:46
已编辑
门头沟学院 C++
只写bug的程序媛:本科能找到好的,真不建议读研,提前占坑比较好,本科找不到好的,也不建议读研,因为两三年之后压力只会更大,唯一的解就是行业好起来
点赞 评论 收藏
分享
02-16 13:52
门头沟学院 Java
给🐭🐭个面试机会吧:嘿,mvbatis
点赞 评论 收藏
分享
牛客网
牛客企业服务