以下程式碼送下去沒有TLE,卻WA了,求救
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map<char,int> m; //紀錄出現次數 key:編號 value:出現次數
int n;
string s,cut;
getline(cin,s);
for(int i=0 ; i<s.size() ; i++){
if(s[i]==' '){
continue;
}
else{
m[s[i]]++;
}
}
for(auto i:m){
if(i.second%3==2){
cout<<i.first;
return 0;
}
}
return 0;
}
以下程式碼送下去沒有TLE,卻WA了,求救
#include
using namespace std;
int main()
{
unordered_map m; //紀錄出現次數 key:編號 value:出現次數
int n;
string s,cut;
getline(cin,s);
for(int i=0 ; i
if(s[i]==' '){
continue;
}
else{
m[s[i]]++;
}
}
for(auto i:m){
if(i.second%3==2){
cout< return 0;
}
}
return 0;
}
你在判斷讀到資料的是否為石頭編號
如果是則該石頭數量+1的部分
m[s[i]]++;
這行應該錯了
因為石頭編號可能是二位數字以上
比方說12
照你的讀法
會讀成1號石頭和2號石頭而不是12號( ˶^ᵕ'˶)b