The problem is from codeforces: http://codeforces.com/problemset/problem/180/C
Let n be the number of lower-cases that have encountered so far from left to right; So everytime there is an uppercase letter, you check if n > 0, then increase the answer and decrease n.
So letter by letter, we virtually change any past lowercase letters to uppercases.
#!/usr/bin/env python from sys import stdin s = stdin.readline() ans = 0 a = 0 for i in s: if i.islower(): a += 1 elif i.isupper() and a > 0: a -= 1 ans += 1 print ans
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
183 wordsloading...
Last Post: Codeforces: A. Winner
Next Post: GCD and LCM