首页 > 试题广场 >

数颜色

[编程题]数颜色
  • 热度指数:1647 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定一个只包含 ``\texttt{R}``、``\texttt{G}``、``\texttt{B}`` 的字符串 S(代表一条彩虹的颜色序列),统计并``\text{(R,G,B)}`` 形式输出三种字母各出现多少次。

输入描述:
\hspace{15pt}一行输入字符串 S\ (1\leqq|S|\leqq10^5),仅含大写字母 ``\texttt{R}``、``\texttt{G}``、``\texttt{B}`` 


输出描述:
\hspace{15pt}按 ``\text{(R,G,B)}`` 形式输出计数结果,分别表示三种字符 ``\texttt{R}``、``\texttt{G}``、``\texttt{B}`` 各自的出现次数。
示例1

输入

RRGBBRG

输出

(3,2,2)
头像 玄骨
发表于 2025-10-24 22:28:44
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; in 展开全文
头像 何成95
发表于 2025-10-25 16:15:55
s = input() r, g, b =0, 0, 0 for c in s: if c=='R': r += 1 elif c=='G': g += 1 elif c=='B': b += 1 print(f'({r}, 展开全文
头像 Zhitong
发表于 2025-07-28 16:38:23
S = input().upper() num_r = 0 num_g = 0 num_b = 0 for i in S: if i == "R": num_r += 1 if i == "G": num_g + 展开全文
头像 李茂林哈哈
发表于 2025-11-11 13:00:14
#include <iostream> using namespace std; int main() { int R=0; int G=0; int B=0; string a; cin>>a; for(int i=0;i< 展开全文
头像 讲道理的花生米少糖去冰
发表于 2025-06-28 19:43:14
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () = 展开全文
头像 Wind_9233
发表于 2025-06-26 21:47:47
import sys a = sys.stdin.readline() countR = a.count("R") countG = a.count("G") countB = a.count("B") print(f"({co 展开全文
头像 丨阿伟丨
发表于 2025-08-27 12:05:36
题目链接 数颜色 题目描述 给定一个只包含大写字母 'R', 'G', 'B' 的字符串 ,代表一条彩虹的颜色序列。请统计这三种字母各出现了多少次,并按照 (R_count,G_count,B_count) 的格式输出结果。 解题思路 这是一个基础的字符计数问题。最直接的方法是遍历整个字符串,并为每 展开全文
头像 神耶避
发表于 2025-08-07 21:20:05
#include <iostream> using namespace std; int main() { string s; cin>>s; int cnt1=0,cnt2=0,cnt3=0; for(char i:s){ if(i=='R'){ 展开全文
头像 牛客229068068号
发表于 2025-07-26 21:16:25
color = list(input()) n =len(color) list1 =[] count_r =0 count_g =0 count_b =0 for i in range(0,n): if(color[i] == 'R'): count_r +=1 展开全文
头像 duire
发表于 2025-09-16 19:19:19
#include<bits/stdc++.h> using namespace std; int main(){ string s; int a=0,b=0,c=0; cin>>s; for(int i=0;i<s.size();i++){ if(s[i]= 展开全文