Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int C(int x, int y){
  6. int ans = 1;
  7. for (int i = x; i > x - y; i--)
  8. ans = ans * i / (x - i + 1);
  9. //printf("C(%d,%d)=%d\n", x, y, ans);
  10. return ans;
  11. }
  12.  
  13. int main(){
  14. string s;
  15. int i,j;
  16. while (cin >> s, s != "0"){
  17. int ans = 0;
  18. for (i = 1; i < s.size();i++)
  19. if (s[i] <= s[i - 1]){
  20. cout << 0 << endl;
  21. break;
  22. }
  23. if (i != s.size())continue;
  24. for (i = 1; i < s.size(); i++)
  25. ans += C(26, i);
  26. for (i = 0; i < s.size()-1; i++){
  27. int a = s[i] - 'a' - (i - 1 >= 0 ? s[i - 1] - 'a' + 1 : 0);
  28. int b = 26 - (i - 1 >= 0 ? s[i - 1] - 'a' + 1 : 0);
  29. for (j = 1; j <= a;j++)
  30. ans += C(b-j,s.size()-i-1);
  31. }
  32. ans += s[i] - 'a' + 1 - (i - 1 >= 0 ? s[i - 1] - 'a' + 1 : 0);
  33. cout << ans << endl;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement