UVA 712 S-Tree_Uva

來源:互聯網
上載者:User

總結規律的題目,輸入的時候如果是X1,X2,X3,那麼X1對應的權值為4,X2對應的權值為2,X3對應的權值為1,其他的輸入依此類推,都是以2為基礎的值。對於後續的待判斷的輸入就計算相應的值,這些值就是在數組中的位置,按照位置找出元素並且輸出就行了。具體的實現見原始碼:

#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>using namespace std;int n;int main(){int amount = 0;while (cin >> n){amount++;if (n == 0) break;vector<int> order;for (int i = 0; i < n; i++){string s;cin >> s;int index = 0;for (int j = 1; j < s.size(); j++){index = index * 10 + (s[j]-'0');}order.push_back(index);}string data;cin >> data;int m;cin >> m;vector<char> result;for (int i = 0; i < m; i++){string d;cin >> d;int index = 0;for (int j = 0; j < order.size(); j++){index = index * 2 + (d[order[j]-1]-'0');}result.push_back(data[index]);}cout << "S-Tree #"<<amount<<":" << endl;for (int i = 0; i < result.size(); i++) cout << result[i];cout << endl << endl;}return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.