NOI 1.7.32:行程長度編碼(字符串,使用toupper)

鏈接:http://noi.openjudge.cn/ch0107/32/

toupper和tolower函數字符轉大寫和轉小寫

#include<ctype.h>
#include<cstdio>
#include<cstring>
using namespace std;
char s[1500];
int main()
{
	//freopen("t.txt","r",stdin);
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++)
	{
		s[i]=toupper(s[i]);
	}
	char p=s[0];
	int cnt=1;
	for(int i=1;i<strlen(s);i++)
	{
		if(s[i]!=p)
		{
			printf("(%c,%d)",p,cnt);
			cnt=1;
			p=s[i];
		}else
		{
			cnt++;
		}
	}
	printf("(%c,%d)",p,cnt);
	return 0; 
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章