123 words
1 minutes
[BOJ] 암호
암호
TimeLimit | MemoryLimit | Condition | TAG |
---|---|---|---|
2s | 128MB | (1 ≤ pw ≤ 1,000,000 1 ≤ words ≤ 100) | Implementation |
그냥 나와있는 조건대로 구현하면 된다.
정답 코드
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
using ll = long long;
string pw, words;
char seq[150];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> words;
cin >> pw;
for(int i = 0; i < words.size(); i++){
if(seq[words[i]] > 0) continue;
seq[words[i]] = i+1;
}
ll cycle = words.size();
ll result = seq[pw[pw.size() - 1]];
for(int i = pw.size() - 2; i > -1; i--){
result += seq[pw[i]] * cycle;
result %= 900528;
cycle *= words.size();
cycle %= 900528;
}
cout << result;
return 0;
}