首页 > 试题广场 >

不要三句号的歪

[编程题]不要三句号的歪
  • 热度指数:11956 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}在书写超过 3 个的连续的数字时,我们通常会将第一、二项和最后一项写出,中间的部分使用三个英文句号作为省略号 \texttt{...} 替代,例如,2,3,\texttt{...},7 其实就是使用省略号省略了 4,5,6 这三个数字。
\hspace{15pt}现在,对于给定的数列,你需要直接求解出省略了多少数字。

输入描述:
\hspace{15pt}在一行上输入一个长度不超过 20 的字符串。具体的规范为:仅包含三个无符号十进制整数 a,b,c \left( 0 \leq a,b,c \leq 10^{12};\,a + 1 =b;\,b + 1 <c \right) ,形如 \underline{a}\texttt{,}\underline{b}\texttt{,...,}\underline{c};数字 ab 间使用一个半角逗号间隔;省略号部分由三个连续半角句号构成,且前后各有一个半角逗号。


输出描述:
\hspace{15pt}在一行上输出一个整数代表被省略的数字数量。
示例1

输入

2,3,...,7

输出

3
示例2

输入

1,2,...,100000000

输出

99999997
#include <iostream>
using namespace std;
int main() {
    long long int a,b,c;
    scanf("%lld,%lld,...,%lld",&a,&b,&c);
    cout << (c-b-1) << endl;
}
发表于 2025-04-06 14:28:20 回复(0)
a,b,c,d = (map(str,input().split(",")))
print(int(d)-int(a)-2)

发表于 2025-03-03 14:36:46 回复(0)
arr = list(input().strip().split(','))
b, c = arr[1], arr[-1]
print(int(c) - int(b) - 1)


发表于 2025-05-27 14:45:35 回复(0)
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;

    vector<string> tokens;
    string token;
    istringstream tokenstring(s);

    while (getline(tokenstring, token, ',')) {
        tokens.push_back(token);
    }

    long long last = stoll(tokens.back());

    long long second = stoll(tokens[1]);

    long long count = last - second -1;

    cout << count;
}
// 64 位输出请用 printf("%lld")
发表于 2026-02-01 12:13:53 回复(0)
import java.math.BigInteger;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String[] str=in.nextLine().split(",");
            BigInteger n=new BigInteger( "1");
            BigInteger b=new BigInteger( str[1]);
            BigInteger c=new BigInteger( str[3]);
            System.out.println(c.subtract(b.add(n)));
        }
    }
}
发表于 2026-01-20 13:43:37 回复(0)
#include <iostream>
#include<string>
using namespace std;

int main() {
    string a;
   long long int n,p;
    for(int i = 0; i < 4;i++ ){
        getline(cin,a,',');
        if(i == 1) {n = stoll(a);}
        if(i == 3) {p = stoll(a);}

    }
    cout<< p-n-1;
    return 0;
}
发表于 2026-01-13 16:33:08 回复(0)
s = input().split(',')
a = eval(s[3])-eval(s[1])-1
print(a)
发表于 2026-01-09 12:01:24 回复(0)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    string str;
    while (cin >> str) { // 注意 while 处理多个 case
        int len = str.length();
        int pos = len - 1;
        long long a = 0, b = 0, c = 0;
        int cnt = 0;
        vector<char> vc, vb, va;
        while (pos >= 0) {
            while (str[pos] != ',') {
                vc.push_back(str[pos]);
                pos--;
            }
            pos -= 5;
            while (str[pos] != ',') {
                vb.push_back(str[pos]);
                pos--;
            }
            pos = -1;
        }
        reverse(vc.begin(), vc.end());
        reverse(vb.begin(), vb.end());
        for (auto iter = vc.begin(); iter != vc.end(); ++iter) {
            c = c * 10 + *iter - '0';
        }
        for (auto iter = vb.begin(); iter != vb.end(); ++iter) {
            b = b * 10 + *iter - '0';
        }
        cout << c - b - 1 << endl;
    }
}
// 64 位输出请用 printf("%lld")

发表于 2025-12-17 20:35:47 回复(0)
假如不止一个“...”

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        List<String> list = Arrays.asList(in.nextLine().split(","));
        int i = list.indexOf("...");
        long res = 0;
        while (i != -1) {
            res += Long.valueOf(list.get(i + 1)) - Long.valueOf(list.get(i - 1))-1;
            list = list.subList(i+1, list.size());
            i = list.indexOf("...");
        }
        System.out.println(res);
    }
}

发表于 2025-11-25 23:29:15 回复(0)
while True:
    try:
        a, b, _, c = input().split(",")
        print(eval(f"{c}-{b}-1"))
    except:
        break

发表于 2025-11-21 15:05:23 回复(0)
s=input().strip()
part1,part2=s.split(",...,")#使用split(",...,")将字符串分为前后两部分
a_str,b_str=part1.split(",")#使用split(",")将字符串分为2 3两部分 也就是a和b的字符串部分
a=int(a_str)
b=int(b_str)
c=int(part2)
print(c-a-2)
发表于 2025-11-20 10:30:57 回复(0)
#include <iostream>
#include <string>
using namespace std;

int main() {
    long long a,b,c;
    char comma,dot1,dot2,dot3,comma2;
    cin>>a>>comma>>b>>comma>>dot1>>dot2>>dot3>>comma2>>c;
    cout<<c-b-1;
}
发表于 2025-11-19 21:25:08 回复(0)
#include <iostream>
using namespace std;

int main() {
    string s;
    long int m,n;
    for(int i=1;i<=4;i++){
    getline(cin,s,',');
    if(i==2){m=stoi(s);}
    if(i==4){n=stol(s);}
    }
    cout<<n-m-1;
}
// 64 位输出请用 printf("%lld")

发表于 2025-11-16 16:49:44 回复(0)
#include <iostream>
#include <sstream>
using namespace std;

int main() {
    long long a, b, c;
    scanf("%lld,%lld,...,%lld", &a, &b, &c);
    cout << c - b - 1;
}
// 64 位输出请用 printf("%lld")
最长20位的字符串 去掉7个占位的符号, 14位减法int不够但是long long足够了,不需要使用高精度减法
发表于 2025-10-25 02:08:45 回复(0)
input1 = input().split(',')
print(int(input1[-1]) - int(input1[(len(input1) - 3)]) - 1)
发表于 2025-10-13 17:31:43 回复(0)
注意要长整型存储即可
#include <stdio.h>
//这么简单?
int main() {
    long int a, b,c;
    scanf("%ld,%ld,...,%ld",&a,&b,&c);
    printf("%ld",c-b-1);
    return 0;
}


发表于 2025-10-09 19:12:22 回复(0)
a = input().split(',') for i in range(len(a)): if a[i] == '...':
        n = int(a[i+1])-int(a[i-1])-1 print(n)
发表于 2025-09-24 14:27:24 回复(0)
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String[] arr = in.nextLine().split(",");
        int n = arr.length;
        long prev = 0L, next = 0L;
        for(int i = 1; i < n - 1; i++){
            if(arr[i].equals("...")){
                prev = Long.parseLong(arr[i - 1]);
                next = Long.parseLong(arr[i + 1]);
            }
        }
        System.out.println(next - prev - 1);
    }
}
发表于 2025-08-30 16:38:26 回复(0)
#include <stdio.h>
int main() {
    long int a, b,c;
   scanf("%ld,%ld,...,%ld",&a,&b,&c);
   printf("%ld",c-b-1);
    return 0;
}
设置输入格式+长整型即可。这种简单的题就喜欢把例子的数搞的特别大
发表于 2025-08-21 18:48:58 回复(0)
a = input().split(",")
print(int(a[3])-int(a[1])-1)
发表于 2025-07-22 13:24:09 回复(0)