Comet OJ c1847

c1847

更好的博客阅读http://cconstantine.xyz/2020/03/15/c1847/

一道简单的字符串比较。

枚举每一位,进行累加。

这里用到了三目运算符。

条件 ? 若为真,则执行该处语句 : 若为假,则执行该处语句; 

所以代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using std::cin;using std::cout;using std::cerr;using std::endl;

const int mmax = 100000;

char s[mmax + 10];
int len,ans = 0;

int main(){

	std::ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin>>len;
	cin>>s;

	for(int i = 0;i < len;++i){
		s[i] == 'G' ? ++ans:ans; 
	}

	cout<<ans;
	return 0;
}

原题地址https://www.cometoj.com/problem/1847

posted @ 2020-03-15 22:56  CConstantine  阅读(118)  评论(0)    收藏  举报