关于一些初级ACM竞赛题目的分析和题解(三)。

266A A. Stones on the Table
There are n stones onthe table in a row, each of them can be red, green or blue. Count the minimumnumber of stones to take from the table so that any two neighboring stones haddifferent colors. Stones in a row are considered neighboring if there are noother stones between them.
Input
The first linecontains integer n (1 ≤ n ≤ 50) — thenumber of stones on the table.
The next linecontains string s, which represents the colors of thestones. We'll consider the stones in the row numbered from 1 to n from leftto right. Then the i-th character s equals"R", ifthe i-th stone isred, "G", if it'sgreen and "B", if it'sblue.
Output
Print a singleinteger — the answer to the problem.
Examples
input
3
RRG
output
1
input
5
RRRRR
output
4
input
4
BRBG
output
0
这道题很好理解 要求连续的字母不同,字母个数【0,50】, 输入一行字母,问删去多少个字母才能达到要求,上代码:#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,i,m;
char s[100]; // 定义字符串
main()
{cin>>n>>s; // 输入n和字符串
for (i=0;i<n-1;i++)
{ if (s[i]==s[i+1]) m++; } // 判断相等条件 并计数
cout<<m; // 输出计数值
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int a,b,c;
char s[1100]; //定义字符串
scanf("%s",s); // 输入字符串
if (s[0]>=97) s[0]-=32; // 判断条件 并作出执行
printf("%s",s); // 输出字符串
}
好了,今天做的题也涉及到了ASCII码的一些内容,众所周知若是用 %d 来输出一个字母时 输出的是该字母在ASCII上对应的数字 但作为一个竞赛人 也应该记住一些常用的 如 65- A 到 90-Z
int a; a='0'; printf("%d",a); // 这样的话输出的结果是 48
int a; a=0; printf("%d",a); // 这样的话就输出的只是 0 这个值了