Codeforces (纪念第一道自己做的题)

B. Skibidus and Ohio
time limit per test1 second
memory limit per test256 megabytes
Skibidus is given a string s that consists of lowercase Latin letters. If s contains more than 1 letter, he can: Choose an index i
(1≤i≤|s|−1, |s| denotes the current length of s) such that si=si+1. Replace si with any lowercase Latin letter of his choice. Remove si+1 from the string.
Skibidus must determine the minimum possible length he can achieve through any number of operations.

Input
The first line contains an integer t (1≤t≤100) — the number of test cases.

The only line of each test case contains a string s (1≤|s|≤100). It is guaranteed s only contains lowercase Latin letters.

Output
For each test case, output an integer on the new line, the minimum achievable length of s

Answer

def cal(s)
  l = s.squeeze.length
  if l == s.length
    return l
  else
    return 1
  end
end
n = gets.to_i
for i in 1..n
  s = gets.to_s.chomp
  puts cal(s)
end
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容