Anton and Letters
Anton and Letters
2 seconds
256 megabytes
standard input
standard output
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved
bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed,
separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
{a, b, c}
3
{b, a, b, a}
2
{}
0
题意:推断集合里元素的个数。即不算反复的。
AC代码:
import java.util.*;
public class Main { public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String s=scan.nextLine();
char a[]=new char[s.length()];
a=s.toCharArray();
int b[]=new int[100];
for(int i=0;i<s.length();i++){
if(a[i]!=' '&&a[i]!=','&&a[i]!='{'){
b[a[i]-'a']=1;
}
if(a[i]=='}') break;
}
int ans=0;
for(int i=0;i<26;i++){
if(b[i]==1)
ans++;
}
System.out.println(ans);
} }
Anton and Letters的更多相关文章
- cf443A Anton and Letters
A. Anton and Letters time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- A. Anton and Letters
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Y - Anton and Letters
Problem description Recently, Anton has found a set. The set consists of small English letters. Anto ...
- Codeforces Round #253 (Div. 2) A. Anton and Letters
题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm ...
- Codeforces Round 253 (Div. 2)
layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #379 (Div. 2) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- C - Anton and Danik
Problem description Anton likes to play chess, and so does his friend Danik. Once they have played n ...
- 【77.39%】【codeforces 734A】Anton and Danik
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [LeetCode] Remove Duplicate Letters 移除重复字母
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
随机推荐
- 跟渣渣辉玩ffms
[SQL] /* Navicat MySQL Data Transfer Source Server : root Source Server Version : 50717 Source Host ...
- hihoCoder 简单计算器
数据结构的入门题,理解倒是不复杂,用两个栈就行(一个存数字一个存符号).对于我这样的弱弱没事练练编码能力还是不错的. 注意运算优先级即可.(过两天回科大了,下次再做题也不知道何时,ACM生涯两铜收场o ...
- 字符串转为JSON对象
经常写字符串转为JSON对象,但是每次没有说一次就成功的,老是搞错属于哪个包的方法,遂记录一下 JSONObject.parseObject(str);这个方法需要导入包 com.alibaba.fa ...
- [Swift]LeetCode1066. 校园自行车分配 II | Campus Bikes II
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- C#之经理评分系统
PM类,几乎全是属性 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- JavaScript 原型和引用趣点
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- JDBC: 批量处理提高SQL处理速度
引用:忘了 当需要成批插入或者更新记录时.可以采用Java的批量更新机制,这一机制允许多条语句一次性提交给数据库批量处理.通常情况下比单独提交处理更有效率 JDBC的批量处理语句包括下面两个方法: a ...
- 实现Android-JNI本地C++调试
1. 原文链接:NDK单步调试方法 如有问题或者版权要求,请拜访原作者或者通知本人. 最近为了性能需求,开始搞JNI,白手起搞真心不容易.中间差点崩溃了好几次,最终总算得到一点心得. JN ...
- 读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++]
读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++] 第2章 数据和基本类型 1. 整型 2. 习题:左值和右值 3. C++关键字/保留字和操作符替代值 4. 声明 ...
- mvc登录授权特性
public class CommonAuthorize : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContex ...