Skip to content

Commit

Permalink
Solved EDIT.
Browse files Browse the repository at this point in the history
  • Loading branch information
natansh committed Jun 3, 2013
1 parent fae6c58 commit 70878b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions EDIT/source.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
int capital[1001], non_capital[1001];
char s[1001];

int i, j;

while(scanf("%s", s) != EOF) {
int l = strlen(s);

for(i = 0; i <= l; ++i) {
capital[i] = 0;
non_capital[i] = 0;
}

for(j = l - 1; j >= 0; --j) {
capital[j] = non_capital[j + 1] + (isupper(s[j])? 0: 1);
non_capital[j] = capital[j + 1] + (isupper(s[j])? 1: 0);
}
printf("%d\n", (capital[0] < non_capital[0])? capital[0]: non_capital[0]);
}
return 0;
}
23 changes: 23 additions & 0 deletions EDIT/source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python

def min_dist(m):
length = len(m)
capital = [0] * (length + 1)
non_capital = capital[:]

for i in range(length-1, -1, -1):
capital[i] = non_capital[i+1] + (0 if m[i].isupper() else 1)
non_capital[i] = capital[i+1] + (1 if m[i].isupper() else 0)

return min(capital[0], non_capital[0])

def main():
while True:
try:
m = raw_input()
print str(min_dist(m))
except EOFError:
break

if __name__ == "__main__":
main()

0 comments on commit 70878b6

Please sign in to comment.