UVA 1225 字符串处理

背景:无。

#include<stdio.h>
#include<string.h>
int main(void){
  int t,str[10];
  scanf("%d",&t);
  while(t--){
  	int n;
  	memset(str,0,sizeof(str));
  	scanf("%d",&n);
  	for(int i=1;i<=n;i++){
  		if(i/1000) {str[i/1000]++;str[(i/100)%10]++;str[(i/10)%10]++;str[i%10]++;}
  		else if(i/100) {str[(i/100)%10]++;str[(i/10)%10]++;str[i%10]++;}
  		else if(i/10) {str[(i/10)%10]++;str[i%10]++;}
  		else str[i]++;
  	}
  	for(int i=0;i<10;i++){
  		if(i) printf(" ");
  		printf("%d",str[i]);
  	}
  	printf("\n");
  }
  return 0;
}

时间: 2024-08-30 14:19:54

UVA 1225 字符串处理的相关文章

UVa 1225 Digit Counting --- 水题

UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现的次数,先将cnt初始化为0,接着让i从1枚举到n, 对每个i,处理以活的i的每一个位置上的数,并在相应的cnt下标上+1 最后输出cnt数组即可 /* UVa 1225 Digit Counting --- 水题 */ #include <cstdio> #include <cstring

UVa 10340 字符串基础

背景:小紫书习题,开始数组开小了runtime error了一次,显然数组越界.复杂度:O(max(A的长度,B的长度)). 题意:看字符串A是不是字符串B的子串.直接顺序扫描即可. #include<stdio.h> #include<string.h> char str[1000000],ttr[1000000]; int main(void){ while(scanf("%s %s",str,ttr)!=EOF){ int j=0,sj=strlen(st

UVa 232 字符串处理、

背景:做了三个半小时,代码能力堪忧啊,各种调试,各种出错,要分析一下,这些错点尽量不能再错. 学习:1.对于字符串数组,要把每一行都开大一位,该位用来存放'\0',否则将会出现未知输出.也就是说:字符串二维数组的每一行都可以看做一个字符数组,结尾都有一个'\0'.printf在用'%s'格式符输出字符串,总是从给定的首地址开始,遇到'\0'结束. 2.写程序的时候要有动态的眼光来看待当前写下的代码运行时的样子.运行出错不要理解单步调试,因先猜测是哪里错了,先看代码在脑中模拟. #include<

UVa 12206 (字符串哈希) Stammering Aliens

体验了一把字符串Hash的做法,感觉Hash这种人品算法好神奇. 也许这道题的正解是后缀数组,但Hash做法的优势就是编码复杂度大大降低. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 const int maxn = 40000 + 10; 7 const int x = 123; 8 int n, m, pos; 9 unsigne

UVA 1585 字符串处理

背景:小紫书上习题 学习:1.条件运算符?:: 的运用可以简化,高效代码.?的优先级大于=,小余算术和关系运算符.与多重赋值语句一样采用右结合.(用到了dp的思想) 代码: #include<stdio.h> #include<string.h> int main(void){ int num[80]; char str[81]; int t; scanf("%d",&t); while(t--){ int sum = 0; scanf("%s

紫书第三章练习题:UVA 1225 Digit Counting by 15邱盼威

来源:http://m.blog.csdn.net/article/details?id=70861055 Trung is bored with his mathematicshomeworks. He takes a piece of chalk and starts writing a sequence ofconsecutive integers starting with 1 to N (1 < N < 10000). After that, hecounts the number

数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. 13 string=12345678910111213 carr[1]++.carr[2]++.carr[3]++....carr[1]++.carr[1]++.carr[1]++.carr[2]++.carr[1]++.carr[3]++ AC Code: import java.util.Sc

Digit Counting UVA - 1225

Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 toN(1 < N < 10000) . After that, he counts the number of times each digit (0 to 9) appears in the sequence

UVa 1225 - Digit Counting - ACM/ICPC Danang 2007 解题报告

1.题目大意 把前n$n\le 10000$个整数顺次写在一起:12345678910111213……计算0~9各出现了多少次. 2.思路 第一想法是打表,然而觉得稍微有点暴力.不过暂时没有想到更好的办法了,写完看了一下其它人的思路好像也差不多是打表的思路. 3.应注意的问题 (1)首先是格式问题,我第一次提交的时候PE了,因为没有意识到空格也会有影响.最开始我的最后一段代码是: for(i=0;i<10;i++) printf("%d ",s[n][i]); printf(&q