Blue Bridge Cup training case conversion algorithm questions

Case conversion algorithm training questions

Resource constraints
Time limit: 1.0s memory limit: 256.0MB
Problem Description
  input a string, the uppercase characters to lowercase, uppercase becomes lowercase, and then outputs the
input format
  acbAB
output format
  ACBab
sample input
an input example of the subject requirements are met.
Example:
acbAB
sample output from
the sample corresponding to the above input and output.
Example:
ACBab
data size and Conventions
  input data range of each number.
  Example: 0 <n, m <100 , 0 < = the number of each matrix <= 1000.

Ideas: sensitive determination, plus 32 uppercase to lowercase, uppercase subtracting 12 becomes lower case.

code show as below:

#include<iostream>
#include<string.h>
using namespace std;
int main(){
	char a[106];
	int i,l;
	cin>>a;
	l=strlen(a);
	for(i=0;i<l;i++){
		if(a[i]>='a' && a[i]<='z'){
			a[i]-=32;
		}
		else{
			a[i]+=32;
		}
	}
	cout<<a;
}
Published 51 original articles · won praise 47 · views 2005

Guess you like

Origin blog.csdn.net/weixin_45269353/article/details/104571338