//未完成
#include<iostream>
#include<stdlib.h>
using namespace std;
int sumT(int sum)
{
int sumA=10;
while(sumA / 10 != 0){
sumA = 0;
while(sum/10 != 0)
{
sumA += sum%10;
sum /= 10;
}
sumA += sum;
sum = sumA;
}
return sum;
}
string num = "0123456789";
int main(void)
{
string a;
while(getline(cin,a))
{
string b;
int n;
int sumM = -1,sumN = 0,sumZ = 0;
for(int j=0;j<a.length();j++)
{
for(int k=0;k<10;k++)
{
if(a[j] == num[k])
{
sumZ += k;
}
}
}
sumZ = sumT(sumZ);
cin>>n;
for(int i=0;i<n;i++)
{
cin.ignore();
getline(cin,b);
int sum = 0;
for(int j=0;j<b.length();j++)
{
for(int k=0;k<10;k++)
{
if(b[j] == num[k])
{
sum += k;
}
}
}
sum = sumT(sum);
int t = abs(sum-sumZ);
if(sumM > t || sumM == -1)
{
sumM = t;
sumN = i+1;
}
}
cout<<sumN<<'\n';
cin.ignore();
}
return 0;
}
//未完成
#include
#include
using namespace std;int sumT(int sum)
{
int sumA=10;
while(sumA / 10 != 0){
sumA = 0;
while(sum/10 != 0)
{
sumA += sum%10;
sum /= 10;
}
sumA += sum;
sum = sumA;
}return sum;
}
string num = "0123456789";int main(void)
{
string a;while(getline(cin,a))
{
string b;
int n;
int sumM = -1,sumN = 0,sumZ = 0;for(int j=0;j {
for(int k=0;k<10;k++)
{
if(a[j] == num[k])
{
sumZ += k;
}
}}
sumZ = sumT(sumZ);
cin>>n;for(int i=0;i {
cin.ignore();
getline(cin,b);int sum = 0;
for(int j=0;j {
for(int k=0;k<10;k++)
{
if(b[j] == num[k])
{
sum += k;
}
}
}sum = sumT(sum);
int t = abs(sum-sumZ);
if(sumM > t || sumM == -1)
{
sumM = t;
sumN = i+1;
}}
cout< cin.ignore();
}
return 0;
}
你沒發現從第二個追求者開始特別數就都錯了嗎?
你的cin.ignore()會把生日的第一個數字吃掉