Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int C(int x, int y){
- int ans = 1;
- for (int i = x; i > x - y; i--)
- ans = ans * i / (x - i + 1);
- //printf("C(%d,%d)=%d\n", x, y, ans);
- return ans;
- }
- int main(){
- string s;
- int i,j;
- while (cin >> s, s != "0"){
- int ans = 0;
- for (i = 1; i < s.size();i++)
- if (s[i] <= s[i - 1]){
- cout << 0 << endl;
- break;
- }
- if (i != s.size())continue;
- for (i = 1; i < s.size(); i++)
- ans += C(26, i);
- for (i = 0; i < s.size()-1; i++){
- int a = s[i] - 'a' - (i - 1 >= 0 ? s[i - 1] - 'a' + 1 : 0);
- int b = 26 - (i - 1 >= 0 ? s[i - 1] - 'a' + 1 : 0);
- for (j = 1; j <= a;j++)
- ans += C(b-j,s.size()-i-1);
- }
- ans += s[i] - 'a' + 1 - (i - 1 >= 0 ? s[i - 1] - 'a' + 1 : 0);
- cout << ans << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement