Advertisement
royalsflush

Referência para LA 3540 (Luiza)

Apr 6th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int cnt=0;
  7. char str[30];
  8. int n,_42=1;
  9.  
  10. void doit(int pos, int last) {
  11.     if (pos==n) {
  12.         cnt++;
  13.         return;
  14.     }      
  15.  
  16.     int acum=0;
  17.     for (int i=pos; i<n; i++) {
  18.         acum+=str[i]-'0';
  19.         if (acum>=last) doit(i+1,acum);
  20.     }
  21. }
  22.  
  23. int main() {
  24.     while (1) {
  25.         scanf(" %s", str);
  26.         if (!strcmp(str,"bye")) break;
  27.         n=strlen(str); cnt=0;
  28.        
  29.         doit(0,-1);
  30.         printf("%d. %d\n", _42++,cnt);
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement