1048 The Hardest Problem Ever

又忘了C++怎么输入带空格的一行字符串了.....

特地写下来,以免又忘了。(注意,cin后要加getchar(),不然后面的getline()会直接读取'\n')

#include <iostream>
using namespace std;

int main()
{
	char s[27] = "VWXYZABCDEFGHIJKLMNOPQRSTU";
	char start[11], end[4], a[300];
	cin>>start;
	while (start[0] - 'S' == 0)
	{
		getchar();
		cin.getline(a, 300);
		cin>>end;
		int len = strlen(a);
		for (int i=0; i<len; i++)
			if (a[i] - 'A' >= 0 && a[i] - 'Z' <=0)
				cout<<s[a[i]-'A'];
			else
				cout<<a[i];
		cout<<endl;
		cin>>start;
	}
}


char*gets(char*buffer);也可以。功能:从stdin流中读取字符串,直至接受到换行符或EOF时停止,并将读取的结果存放在buffer指针所指向的字符数组中。换行符不作为读取串的内容,读取的换行符被转换为null值,并由此来结束字符串。

如 HDOJ 1219 AC Me

#include <iostream>
using namespace std;

int main()
{
	int i, temp;
	int a[26];
	char s[100001];
	while (gets(s))
	{
		for (i=0; i<26; i++)
			a[i] = 0;
		for (i=0; s[i]; i++)
		{
			temp = s[i] - 'a';
			if (temp >= 0)
				a[temp]++;
		}
		for (i=0; i<26; i++)
			cout<<char('a' + i)<<":"<<a[i]<<endl;
		cout<<endl;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值