A - camel Case Editorial by en_translator
In order to find the answer, inspect the characters of \(S\) one by one and check if it is capital. In order to check if a character is capital, use a predefined standard library or method.
The standard library or method depends on languages; for example, C++ has a function std::isupper
, and Python has isupper
method for a string.
Also, when comparing char-type variables, the comparison is done based on the corresponding encoding; in most encoding, the uppercase and lowercase alphabets are assigned in a consecutive region (for example, in ASCII and Unicode, A
-Z
corresponds to \(65\)-\(90\), and a
-z
to \(97\)-\(122\)). Thus, one can determine if each character \(S_i\) in the string \(S\) is uppercase by: ‘A’ \(\leq S_i\) and \(S_i\leq\)‘Z’.
With these method, the problem can be solved.
Sample code in C++ 1:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin>>s;
n=s.size();
for(int i=0;i<n;i++){
if(isupper(s[i])){
cout<<(i+1)<<endl;
}
}
return 0;
}
Sample code in C++ 2:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin>>s;
n=s.size();
for(int i=0;i<n;i++){
if(('A'<=s[i])&&(s[i]<='Z')){
cout<<(i+1)<<endl;
}
}
return 0;
}
Sample code in Python:
s=input()
for i in range(len(s)):
if(s[i].isupper()):
print(i+1)
posted:
last update: