TOJ 3851. Variable Names
来源:互联网 发布:商机助理怎么传淘宝 编辑:程序博客网 时间:2024/06/05 20:36
很难的题目,刚开始错了,比如说输入111时,应该改1个就行,输入2w2,应该改一个,后来参考了大神的代码就知道了。
Ann is crazy about code style so that she prefers the variable names with a good style. She believes that a good variable name should begin with at least one letter, and then zero or more digits.
You know, letters like 'l', 'o', or 'O' is confusing when they are compared with the digits '1' or '0'. Then Ann's variable wouldn't consist of these three letters, 'l', 'o', 'O'. For example, 'var123' is a good name while 'va12r' isn't since the digits '1', '2' is before the letter 'r'.
To let the variables have good names, Ann will change the characters. She can replace a character with another character. That is, Ann can replace one digit or letter with another digit or letter. Ann will replace 2 characters to make 'var12r' a good name, such as 'varxxr'. Also she could just replace the last character 'r', so the name is 'var123'.
Input
There are several test cases. For each test case, there's a line contains a string, which consists of letters and digits. The length of string does not exceed 10^5.
Output
For each test case, print a number which is the least number of characters needs to be replaced to make the variable have a good name.
Sample Input
var12rvarnameloOhi3134sin4we
Sample Output
1035
#include<iostream>#include<string>using namespace std;int main(){char s[100010];int len,l,letter,dight,n,d,x,y,min;while(cin>>s){len=strlen(s);n=0;letter=0;dight=0;x=0;d=0;l=0;y=0;min=100010;for(int i=0;i<len;i++){if(s[i]=='l'||s[i]=='o'||s[i]=='O')n++;else if(s[i]>='0'&&s[i]<='9'){ //break;d++;s[i]='0';//数字为0}else {l++;s[i]='1';//字母为1}}if(s[0]=='0'){s[0]='1';n++;l++;}for(int j=0;j<len;j++){if(s[j]=='1'){if(l+y-x-1<min)min=l+y-x-1;}else if(s[j]=='0'){if(l+y-x<min)min=l+y-x;}if(s[j]=='1')x++;else if(s[j]=='0')y++;}//cout<<n<<" "<<dight<<" "<<m<<" "<<letter<<endl;if(min==100010)min=0;cout<<min+n<<endl;}return 0;}
- TOJ 3851. Variable Names
- PeopleCode Variable Names
- Table of CGI variable names
- The world’s two worst variable names
- TJU-3851Variable Names(贪心)
- Problems mousing over variable names in iPhone debugger
- JavaScript quirk 4: unknown variable names create global variables
- names
- [Code Complete] CH11 The Power of Variable Names 变量名的力量
- Variable
- Variable
- variable
- variable
- Data Names
- echo 'names';
- echo 'names';
- About Names
- Meaningful Names
- HDU 4786 Fibonacci Tree 最小生成树 kruskal算法
- FFT.c
- hdu 1398 Square Coins
- 2014年辛星vim教程秋季版正式完工,特发此贴纪念下
- 国外大牛写的HOOK
- TOJ 3851. Variable Names
- NUMBER BASE CONVERSION(高精度)
- Mysql4.0.20中文乱码
- 算法竞赛入门经典 Dynamic Programming
- hdu 1017 A Mathematical Curiosity
- 1050. String Subtraction (20)
- EBS R12多组织的实现原理
- java面试宝典-传值和传引用
- Python核心编程 练习 第四章