UPC个人训练赛第九场

问题 E: Soundex

题目描述
Soundex coding groups together words that appear to sound alike based on their spelling. For example,“can” and “khawn”, “con” and “gone” would be equivalent under Soundex coding.
Soundex coding involves translating each word into a series of digits in which each digit represents a letter:
1 represents B, F, P, or V
2 represents C, G, J, K, Q, S, X, or Z
3 represents D or T
4 represents L
5 represents M or N
6 represents R
The letters A, E, I, O, U, H, W, and Y are not represented in Soundex coding, and repeated letters with the same code digit are represented by a single instance of that digit. Words with the same Soundex coding are considered equivalent.

输入
Each line of input contains a single word, all upper case, less than 20 letters long.

输出
For each line of input, produce a line of output giving the Soundex code.

样例输入
KHAWN
PFISTER
BOBBY

样例输出
25
1236
11

我写的程序:

#include"iostream"
#include
using namespace std;


char list1[4]= {'B','F','P','V'};
char list2[8]= {'C','G','J','K','Q','S','X','Z'};
char list3[2]= {'D','T'};
char list4[1]= {'L'};
char list5[2]= {'M','N'};
char list6[1]= {'R'};
char list7[8]= {'A','E','I','O','U','H','W','Y'};

int soundex(char letter) {
    for(int i=0; i> word) {
        for(int i=0; i

遇到的问题

  1. 【编译错误】头文件又没写对
  2. 【答案错误】没看清题目要求的是多行输入,且每次输出后需要换行

知识点

问题 H: Square Numbers
题目描述
A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many squ

输入
The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0 < a ≤ b ≤ 100000). Input is terminated by a line containing two zeroes. This line should not be processed.

输出
For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive).

样例输入
1 4
1 10
0 0

样例输出
2
3

我写的程序:

#include"iostream"
#include"math.h"
using namespace std;

int main(){
    int a,b;
    while(cin >> a&&cin >> b&&(a!=0||b!=0)&&a<=b){
        
        int start=(int)sqrt(a);
        if(a==start*start)
        start--;
        
        int end=(int)sqrt(b);
        cout << end-start << endl;
        
    }
} 

犯的错误:

知识点:

问题 I: 面积

题目描述
乐乐的家中共有 n 个长方形,请你帮助乐乐计算一下这些长方形的总面积。

输入
第一行只有一个正整数 n
接下来的 n 行,每行两个正整数:x y,分别表示长方形的长和宽

输出
只有一行且只有一个整数:这些长方形的总面积。

样例输入
3
3 2
5 4
7 3

样例输出

47

提示
32 + 54 + 7*3 = 47。
【数据范围】
对于 70%的数据, 1 < n <= 1 000 , 1 <= y <= x <= 1 000
对于 100%的数据, 1 < n <= 10 000 , 1 <= y <= x <= 100 000

我写的程序:

#include"iostream"
using namespace std;

int main(){
    int n;
    cin>> n;
    int a,b;
    long long sum=0;
    for(int i=0;i> a >>b;
        sum+=(long long)a*(long long)b;
    }
    cout << sum;
} 

犯的错误:

  1. 【答案错误】输出结果最大为10位以上,用int表示不了,得用long long
  2. 【编译错误】头文件没写对

知识点:

  1. int、long、long long的数值范围

问题 L: 排队

题目描述
乐乐的 n 位朋友都拥有唯一的一个编号,编号分别为 1 至 n。某天按到达的时间顺序又给了一个顺序号,此时发现顺序号与多数的朋友编号不一致。乐乐想:如果俩俩交换顺序号,使得每位朋友的编号与顺序号相同,则最少需要交换几次?

输入
包含二行:
第一行只有一个正整数:n,表示乐乐朋友的人数
第二行共有 n 个正整数,分别表示按顺序到达的朋友编号

输出
只有一行且只有一个正整数:最少的交换次数

样例输入
5
4 2 1 5 3

样例输出
3

提示
对于 30%的数据, 1 <= n <= 100
对于 80%的数据, 1 <= n <= 10 000
对于 100%的数据, 1 <= n <= 100 000

我编写的代码:

#include"iostream"
#include"vector"
#include"map"
#include"algorithm"
using namespace std;

int main() {
    int n,loop=0;
    cin >>n;
    int* num=new int[n];
    bool* flag=new bool[n];
    for(int i=0; i> num[i];
        flag[i]==false;
    }
    //找出循环节的个数
    int next,i=0;
    for(int i=0; i

问题:

  1. 如何快速初始化一个标记数组?

参考文章:

  1. 循环节的解释
  2. vector的用法

整型数据范围

Java大数的用法

你可能感兴趣的:(UPC个人训练赛第九场)