有没有大佬给份测试数据或指导下,我总是A不了

#include <iostream>
#include <map>
using namespace std;
map<char ,int> m;
map<int, int> p;
int main() {
    int n=2;
    int x=1;
    for (char i='A';i!='Z';i++,x++){
        if(i=='Q') {
            x--;
            continue;
        }
        m[i]+=n;
        if(x%3==0) n++;
    }
    int num;
    cin>>num;
    string s;
    int temp[7];
    while(num--){
        cin>>s;
        int k=0;
        for (int i=0;i<s.size();i++,k++)
        {
            if(s[i]=='-'){
                k--;
                continue;
            }else if(s[i]>='A'&&s[i]<='Z'){
                temp[k]=m[s[i]];
            }else if(s[i]>='0'&&s[i]<='9'){
                temp[k]=s[i]-'0';
            }
        }
        int q=temp[0];
        for (int j = 1; j <7 ; ++j) {
            q=q*10+temp[j];
        }
        p[q]++;
    }
    map<int ,int>::iterator it;
    int flag=0;
    for(it=p.begin();it!=p.end();it++) {
        if (it->second > 1) {
            printf("%03d-%04d %d\n", it->first / 10000, it->first % 10000, it->second);
            flag = 1;
        }
    }
    if(!flag) cout<<"No duplicates."<<endl;
    return 0;
}

<sstream> 简介

<sstream>库定义了三种类:istringstreamostringstreamstringstream,分别用来进行流的输入、输出和输入输出操作。简单起见,我主要以 stringstream 为重点,讲讲这个STL

简单类型转换 string To int

string result=”10000”;
int n=0;
stream<<result;
stream>>n;  //n等于10000

定义一个通用的类型转换模板

template<typename out_type,typename in_value>
out_type convert(const in_value & t)
{
    stringstream stream; 
    stream<<t;//向流中传值
    out_type result;//这里存储转换结果
    stream>>result;//向result中写入值
    return result;
}

hdu2072实践

统计一篇文章中出现的不同单词的个数,文章由小写字母和空格构成

#include <iostream>
#include <set>
#include <sstream>
using namespace std;
set<string> temp;
string row,input;
int main() {
    while(getline(cin, row)&&row!="#")  //输入一行字符串可以用getline
    {
        temp.clear();
        stringstream str(row); 
        while(str>>input) //输出str中的单词以空格隔开 
            temp.insert(input);
        cout<<temp.size()<<endl;
    }
    return 0;
}

结论

sstream老好用了

The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.

这个题一开始我用的是int类型没考虑到数字特别大的情况,参考了神犇的解题报告后发现其实要用字符串来解决,而且是数论中的一条基本定理,我还循环折腾半天
Digtial Roots=(sum-1)%9+1
看来人丑还是要多读书

本想用最简单最暴力的方法AC的,结果正确但超时,等我想到更好的办法再继续

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int Case=1;
    while(n--)
    {
        int m;
        cin>>m;
        int arr[m];
        int Max=0;
        int l=1,r=m;
        for(int i=0;i<m;i++)
        {
            cin>>arr[i];
            Max+=arr[i];
        }
        for(int i=0;i<m;i++)
        {
            int sum=0;
            for(int j=i;j<m;j++)
            {
                sum += arr[j];
                if (sum > Max) {
                    l = i + 1;
                    r = j + 1;
                    Max = sum;
                }
            }
        }
        cout<<"Case "<<Case<<":"<<endl;
        cout<<Max<<" "<<l<<" "<<r<<endl;
        Case++;
    }
    return 0;
}